Skip to main content

📦 ptal‑api Repository Documentation

tl;dr This repository provides a Python client library (ptal_api) for interacting with the Talisman GraphQL APIs, along with a generator script that automatically creates type‑safe client code from GraphQL schemas.


Table of Contents

  1. What the repository contains
  2. Prerequisites
  3. Installation (as a library)
  4. Project layout
  5. Generating API client code
  6. Using the generated client
  7. Example snippets
  8. Testing
  9. Code Style

What the repository contains

Directory / File Purpose
ptal_api/ Core package that ships the runtime client (Client), authentication providers, and generated schema modules.
ptal_api/schemas/ Destination for the generated GraphQL operation classes (mesh_schema, system_utils_schema, …).
generator_script/ Helper utilities that turn GraphQL introspection files into ready‑to‑use Python modules.
generator_script/generate_script.py Orchestrates the whole generation pipeline: runs ariadne‑codegen, moves files, patches imports, and cleans the code with Ruff.
generator_script/async_base_client.py Base async client class shared by all generated modules.
generator_script/toml_configs/ Ariadne‑codegen configuration (*.toml) for each API.
examples/ Small, ready‑to‑run scripts showing how to use the client (adapter usage, mutation, query, raw execution).
tests/ Test suite for the library.
pyproject.toml / poetry.lock Poetry‑managed project metadata and dependencies.
README.md (this file) High‑level documentation (you are reading it!).
CHANGELOG.md Change history.

Prerequisites

Tool Minimum version Why you need it
Python 3.12+ Required for the async‑first design and the typing features used throughout the code.
Poetry 2.0+ Manages the virtual environment and project dependencies.
ariadne‑codegen latest (install via pip or Poetry) Generates the type‑safe GraphQL client modules from schema files.
ruff latest (install via pip or Poetry) Auto‑formatter and lint fixer applied to generated code.
httpx any Underlying HTTP client used by the generated Client.
keycloak (optional) any Required if you plan to use the KeycloakAuthProvider.
websockets (optional) any Needed only for GraphQL subscriptions.

Install everything with Poetry:

poetry install

Or, if you prefer plain pip:

pip install ariadne-codegen ruff httpx keycloak websockets

Installation (as a library)

Once the generated schemas exist (see the Generating API client code section), you can install the package locally for development:

# From the repository root
poetry build
poetry install

Or use it directly from the source tree:

pip install -e .

Project layout

ptal-api/
│
├─ ptal_api/
│   ├─ __init__.py
│   ├─ client.py                # High‑level GraphQL client wrapper
│   ├─ auth_provider.py         # Abstract authentication base class
│   ├─ keycloak_provider.py     # Keycloak‑based auth implementation
│   ├─ no_auth_provider.py      # No‑auth placeholder
│   ├─ schemas/                 # ← generated GraphQL modules
│   │   ├─ mesh_schema/
│   │   └─ system_utils_schema/
│   └─ ...                      # Additional utilities
│
├─ generator_script/
│   ├─ async_base_client.py     # Shared async client base class
│   ├─ generate_script.py       # Main generation entry point
│   └─ toml_configs/
│       ├─ mesh.toml
│       └─ system_utils.toml
│
├─ examples/
│   ├─ adapter_usage.py
│   ├─ cancel_job.py
│   ├─ get_periodic_job.py
│   └─ raw_execute.py
│
├─ tests/                       # pytest test suite
│
├─ .gitlab-ci.yml               # CI pipeline definition
├─ pyproject.toml               # Poetry project definition
├─ poetry.lock
└─ README.md                    # (this file)

Key modules

Module What it provides
ptal_api.client.Client Thin wrapper around httpx.AsyncClient that knows how to send GraphQL queries/mutations.
ptal_api.auth_provider.AuthProvider Abstract base class for authentication providers.
ptal_api.keycloak_provider.KeycloakAuthProvider Implements AuthProvider using Keycloak OIDC token flow.
ptal_api.no_auth_provider.NoAuthProvider Simple provider returning empty headers (useful for public APIs).
ptal_api.adapter.TalismanAPIAdapter (in examples) Convenience wrapper around the generated client exposing higher‑level domain methods.

Generating API client code

The repository ships a generator script that automates the entire workflow for the two GraphQL APIs (mesh and system_utils). The script:

  1. Validates that it runs from the correct directory.
  2. Calls ariadne‑codegen with the appropriate TOML configuration.
  3. Moves the generated package into ptal_api/schemas/.
  4. Patches imports so they point to the shared ptal_api package (ptal_api.base_model, ptal_api.base_operation, etc.).
  5. Runs Ruff to format the code and fix lint issues.

How to run it

cd ptal-api/generator_script
python generate_script.py

The script will output progress messages such as:

Generating mesh_schema
Ended generating mesh_schema
...
Generating system_utils_schema
Ended generating system_utils_schema

... (ruff output) ...

When it finishes, you’ll find the generated Python modules under:

ptal_api/schemas/mesh_schema/
ptal_api/schemas/system_utils_schema/

Note – If you add a new schema, create a matching *.toml file in generator_script/toml_configs/ and extend the apis tuple in generate_script.py.


Using the generated client

Below is a minimal example that shows how to set up a client with Keycloak authentication and execute a simple query.

import os
import asyncio

from ptal_api.client import Client
from ptal_api.auth_providers import KeycloakAuthProvider
from ptal_api.schemas.mesh_schema.custom_queries import Query as MeshQuery
from ptal_api.schemas.mesh_schema.custom_fields import DocumentFields


async def main() -> None:
    auth = KeycloakAuthProvider(
        auth_url=os.getenv("KEYCLOAK_URL"),
        realm=os.getenv("KEYCLOAK_REALM"),
        client_id=os.getenv("KEYCLOAK_CLIENT_ID"),
        client_secret=os.getenv("KEYCLOAK_CLIENT_SECRET"),
        user=os.getenv("KEYCLOAK_USER"),
        password=os.getenv("KEYCLOAK_PASSWORD"),
    )

    client = Client(url=os.getenv("GRAPHQL_URL"), auth_provider=auth)

    # Example: fetch a document by ID
    document_query = MeshQuery.document(id="12345")
    document_query.fields(
        DocumentFields.id,
        DocumentFields.title,
        DocumentFields.document_content_type,
    )

    response = await client.query(document_query, operation_name="GetDocument")
    print(response)


if __name__ == "__main__":
    asyncio.run(main())

Quick tips

Situation What to do
No auth required Use NoAuthProvider() when constructing Client.
Custom headers Subclass AuthProvider and return the desired Headers.
Subscriptions Ensure websockets is installed and pass a ws:// endpoint to Client.
Adding new GraphQL operations Edit the schema, regenerate with the script, and import the new generated classes under ptal_api.schemas.<api>_schema.

Example snippets

The examples/ directory contains ready‑to‑run scripts that illustrate common patterns:

File Description
adapter_usage.py Shows how to obtain a TalismanAPIAdapter and call a high‑level method (get_document).
cancel_job.py Demonstrates a mutation (CancelJob) with custom fields.
get_periodic_job.py Queries a periodic job using a chain of nested field selections.
raw_execute.py Shows the low‑level client.execute() call for cases where the generated helpers are insufficient (not recommended for everyday use).

You can run any example with:

cd examples
poetry run python <example_name>.py

Remember to set the required environment variables (GRAPHQL_URL, KEYCLOAK_*, etc.) beforehand.


Testing

The repository ships a pytest‑based test suite under tests/. To execute it locally:

poetry run pytest

The CI pipeline (see next section) runs the same command on every merge request, ensuring that new changes keep the library stable.

Code Style

  • Follow the existing formatting (auto‑formatted by Ruff).
  • Keep import statements absolute (from ptal_api.base_model import …).
  • Prefer async functions and await wherever possible.

Metadata

Release files for ptal-api 0.18.8.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ptal-api 0.18.8.0
File Size Uploaded Provenance Actions
ptal_api-0.18.8.0.tar.gz 173.1 kB Without provenance Details for ptal_api-0.18.8.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ptal-api 0.18.8.0
File Interpreter ABI Platform Actions
ptal_api-0.18.8.0-py3-none-any.whl Python 3 none any Details for ptal_api-0.18.8.0-py3-none-any.whl

Total release size: 351.7 kB

Release files / ptal_api-0.18.8.0.tar.gz

Download URL ptal_api-0.18.8.0.tar.gz
Size 173.1 kB
Tags Source
SHA-256 checksum
How to use checksums
cf9ec6718c1999527f84a3e62e6035249c2af9511bf8381e2cc78928b79d0d2a
BLAKE2b-256 checksum
How to use checksums
c2c5b2d0c070f82cf8720e5ca4b61c7b4c47e55a604fd38fee4e9e8d218ff26c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.1 CPython/3.12.13 Linux/5.13.0-28-generic

Release files / ptal_api-0.18.8.0-py3-none-any.whl

Download URL ptal_api-0.18.8.0-py3-none-any.whl
Size 178.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2bf13b4ab8e9d1ee48007d231a10769940d8e26db945adc262e3086eefd03536
BLAKE2b-256 checksum
How to use checksums
31cbcef239ada405dccde76f6e7223655515ef6e3c6a5a7837b7c7f1c0560715
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.1 CPython/3.12.13 Linux/5.13.0-28-generic

Security for ptal-api 0.18.8.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.18.8.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page