Skip to main content
The Validio Software Development Kit (SDK) is a Python package that implements Validio Code, Validio’s Infrastructure-as-Code (IaC) solution. It also comes with a GraphQL client for the Validio API, which uses the same default authentication methods and headers as the Validio CLI. The SDK Reference documents all of the SDK’s public modules, classes, and functions. The client lets you send your queries or mutations as regular strings, and pass a Python dictionary as variable_values. For more information, see Use the SDK client. For worked examples, see the SDK recipes.
The GraphQL client is in beta, and breaking changes may happen.

Install the Validio SDK

The Validio SDK is published as a Python package on PyPI as validio-sdk. You can use a Python package installer, such as pip, to install the SDK in your desired environment:
Bash
The Validio CLI depends on the SDK, so installing validio-cli installs both.

Authentication

You need an API key, made up of an access key and an access secret, to interact with the Validio API. The client finds your credentials automatically, by looking for environment variables and then for a config.json. For the full lookup order, see How the CLI and SDK find credentials. You can create the config.json with the Validio CLI by running validio config init. To specify the credentials yourself, pass a ValidioConfig when you create the client. You can also pass headers, a dictionary of additional headers to send with every request:
Python

Use the SDK client

For more examples of how to use the client, see the SDK recipes.

Send a query

This example creates a client with explicit credentials, sends a sourcesList query with a variable that filters on a namespace, and prints the name of each source:
Python
The client returns the response data as a dictionary, keyed by each top-level field in the query, here sourcesList.

Synchronous or asynchronous

The client is written to be used asynchronously, so it needs an asynchronous runtime. This allows safe concurrent use, and lets you run multiple operations at the same time when needed. To use the client in a non-asynchronous context, wrap the request in asyncio.run:
Python
This is not to be confused with how the server executes operations. When multiple queries are sent in the same request, the server always executes them concurrently, whereas mutations are always executed in sequence. For more information, see the GraphQL documentation.

Use the same client in different threads

To use the client across multiple threads at the same time, use a session. The session is opened before the first request and isn’t closed until all requests are done. Open one with an async with block. The session it returns is a validio_sdk.client.Session, which has the same execute method as the client:
Python