validio-sdk documentation¶
Getting started¶
The Validio SDK implements Validio’s IaC solution. It also comes with a GraphQL client that uses the same default authentication methods and sensible headers as our CLI.
NOTE! The client used in the examples below is in beta and breaking changes may happen.
You can install the Validio SDK through PyPI by running pip install
validio-sdk
.
import asyncio
import os
from validio_sdk.client import Client, ValidioConfig
async def main()
client = Client(
config=ValidioConfig(
endpoint="https://validio.my-company.com",
access_key=os.getenv("VALIDIO_ACCESS_KEY"),
access_secret=os.getenv("VALIDIO_ACCESS_SECRET"),
)
headers={
"X-Custom-Header": "value",
},
)
query = """
query SourcesList($filter: ResourceFilter) {
sourcesList(filter: $filter) {
id
name
segmentations { id }
}
}
"""
variables = {"filter": {"namespaceId": "default"}}
sources = await client.execute(query, variable_values=variables)
for source in sources["sourcesList"]:
print(source["name"])
if __name__ == "__main__":
asyncio.run(main())
Advanced async usage¶
If you want to use the client in multiple parallel executions you need to ensure you create a session that supports this. The reason is that the client needs to open a connection and keep it open for all requests before disconnecting. This is done by using a session context.
The type of the session returned is a validio_sdk.client.Session
.
from validio_sdk.client import Client
async def session_example():
client = Client()
with client as session:
await asyncio.gather(
task1(session),
task2(session),
task3(session),
)