Skip to main content
The Pragmatiks SDK provides Python clients for managing resources programmatically. It offers both synchronous and asynchronous clients, typed responses, and utilities for building providers.

Installation

Quick Start

Authentication

The SDK discovers credentials in this order:
  1. Explicit token - Pass auth_token to the client
  2. Context-specific environment variable - PRAGMA_AUTH_TOKEN_{CONTEXT} (uppercase)
  3. Generic environment variable - PRAGMA_AUTH_TOKEN
  4. CLI credentials file - Tokens stored by pragma auth login

Contexts

Contexts allow switching between environments (e.g., development, staging, production):
Set the default context via environment variable:

PragmaClient

Synchronous client for the Pragmatiks API. Use as a context manager to ensure connections are closed.

Constructor

Context Manager

Health Check

Check if the API is reachable and healthy.

Get Current User

Get information about the authenticated user.
Returns: UserInfo with user_id, email, organization_id, and organization_name. Raises: httpx.HTTPStatusError if not authenticated (401).

Resource Operations

list_resources

List resources with optional filters. Returns dictionaries by default, or typed instances if model is provided.

list_resource_types

List available resource types from deployed providers.
Returns: List of resource definitions with provider, resource, schema, and description.

get_resource

Get a single resource by its identifier.
Raises: httpx.HTTPStatusError if resource not found (404).

apply_resource

Create a new resource or update an existing one.

delete_resource

Delete a resource. The resource enters the deletion lifecycle and is removed after cleanup.
Raises: httpx.HTTPStatusError if resource not found (404).

Dead Letter Operations

Dead letter events are failed lifecycle events that can be retried or discarded.

list_dead_letter_events

List failed events awaiting manual intervention.

get_dead_letter_event

Get details of a specific dead letter event.

retry_dead_letter_event

Retry a single failed event.

retry_all_dead_letter_events

Retry all dead letter events. Returns the count of events retried.

delete_dead_letter_event

Discard a dead letter event without retrying.

delete_dead_letter_events

Bulk delete dead letter events. Must specify either provider or all=True.
Raises: ValueError if neither provider nor all=True is specified.

Provider Deployment

Deploy custom providers to the platform.

list_providers

List all providers for the current tenant.
Returns: List of ProviderInfo with provider_id, current_version, deployment_status, and updated_at.

list_builds

List builds for a provider (newest first, up to 10).
Returns: List of BuildInfo with provider_id, version, status, error_message, and created_at.

push_provider

Upload provider source code and start a build.
Returns: PushResult with version, status, and message.

get_build_status

Check the status of a build by version.
Returns: BuildInfo with provider_id, version, status, error_message (on failure), and created_at.

stream_build_logs

Stream build logs in real-time.

deploy_provider

Deploy a provider to a specific version. If no version is specified, deploys the latest successful build.
Returns: ProviderStatus with status, version, updated_at, and healthy.

get_deployment_status

Check deployment status.
Returns: ProviderStatus with status, version, updated_at, and healthy.

AsyncPragmaClient

Asynchronous client with the same API as PragmaClient. All methods are async.

Async Context Manager

Streaming Build Logs (Async)

Concurrent Operations

Run multiple independent operations concurrently:

Typed Responses

Use typed models for better IDE support and validation. Define models using the SDK base classes.

Resource Model

Using Typed Models

Lifecycle State Enum


Dependencies

When building providers, you can declare dependencies on other resources using the Dependency[T] generic. This provides typed access to the resolved dependency’s outputs.

Error Handling

The SDK raises httpx.HTTPStatusError for API errors. Handle common cases:

Authentication Errors

Timeout Handling

Retry Pattern


File Uploads

Upload files to Pragmatiks storage programmatically:
After uploading, create a pragma/file resource to track the file:

Dependencies and Field References

FieldReference

Reference a specific output field from another resource:

Dependency[T]

For provider authors, declare whole-resource dependencies with typed access:

Owner References

Establish parent-child relationships for cascade deletion:
When the owner resource (my-team) is deleted, owned resources (team-member) are automatically cascade-deleted.

Provider Authoring

The SDK also provides utilities for building providers. See Building Providers for complete documentation.

Key Exports

Quick Example


Next Steps

Building Providers

Create custom providers with lifecycle methods.

Lifecycle Methods

Deep dive into on_create, on_update, and on_delete.

API Reference

Full REST API documentation.

Error Recovery

Handle failures and retry dead letter events.