.. raw:: html
.. image:: static/validio-logo-purple.svg
:width: 240
:alt: Validio AB
.. raw:: html
validio-sdk documentation
===========================
.. toctree::
:maxdepth: 3
:caption: Contents:
modules
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``.
.. code-block:: python
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``.
.. code-block:: python
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),
)
Indices and tables
==================
* :ref:`modindex`
* :ref:`search`