Installation
- uv
- pip
Quick Start
The client auto-discovers credentials frompragma auth login or the environment. Resource operations live on a project handle:
pragma resources apply.
Authentication
The SDK discovers credentials in this order:- Explicit token - Pass
auth_tokento the client - Context-specific environment variable -
PRAGMA_AUTH_TOKEN_{CONTEXT}(uppercase) - Generic environment variable -
PRAGMA_AUTH_TOKEN - CLI credentials file - Tokens stored by
pragma auth login
Contexts
Contexts switch between environments, such as development and production.PragmaClient(context="production") reads PRAGMA_AUTH_TOKEN_PRODUCTION or the credentials file.
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
Thewith block closes the connection on exit. Without it, call close():
Health Check
Get Current User
UserInfo with user_id, email, organization_id, and organization_name.
Raises: httpx.HTTPStatusError if not authenticated (401).
list_resource_schemas
ResourceSchema with provider, resource, config_schema, outputs_schema, and description.
Resource Operations
client.project(project_id) returns a ProjectResources handle. Every resource operation is scoped to that project.
list_resources
model. reveal=True includes sensitive values.
get_resource
httpx.HTTPStatusError if the resource is not found (404).
apply_resource
project_id must match the handle’s project.
Raises: ProjectMismatchError if resource.project_id differs from the handle’s project; httpx.HTTPStatusError if the API rejects the resource.
deactivate_resource
draft. dry_run=True previews the teardown without changing anything.
delete_resource
TeardownResponse with lifecycle_state, impact (every resource the teardown reaches, the requested one first), and dry_run.
wait_ready, wait_deactivated, wait_deleted
ready. wait_deactivated waits for draft and wait_deleted for deleted, with the same parameters. timeout=0 or None waits forever.
Raises: ResourceFailedError if the resource reaches failed; TimeoutError if the timeout expires first.
Dead Letter Operations
Dead letter events are failed lifecycle events that can be retried or discarded.list_dead_letter_events
get_dead_letter_event
retry_dead_letter_event
retry_all_dead_letter_events
delete_dead_letter_event
delete_dead_letter_events
all=True. Returns the count deleted.
ValueError if neither provider nor all=True is specified.
Provider Operations
These methods back thepragma providers commands; see the CLI reference for the workflow. Provider names are namespaced as org/name.
DeploymentResult.status is one of pending, progressing, available, or failed.
AsyncPragmaClient
Asynchronous client with the same API asPragmaClient. All methods are async, and client.project(project_id) returns an AsyncProjectResources handle.
Async Context Manager
Theasync with block closes the connection on exit. Without it, await close():
Concurrent Operations
Run independent operations concurrently:Lifecycle Events
AsyncPragmaClient.stream_lifecycle_events(timeout=None) yields one frame per resource lifecycle transition in your organization. timeout=0 or None streams until you stop consuming.
Typed Responses
Pass a provider’s resource class asmodel to get typed instances back. The response’s config and outputs are validated against that class, so use the class from the installed provider version:
Lifecycle States
LifecycleState is a string enum, so it compares equal to the lifecycle_state string in a dictionary response:
Error Handling
The SDK raiseshttpx.HTTPStatusError for API errors. Handle common cases:
Authentication Errors
PragmaClient(require_auth=True) raises ValueError when no credentials are found. Run pragma auth login or set PRAGMA_AUTH_TOKEN.
Timeout Handling
Requests that exceed the client’stimeout raise httpx.TimeoutException. Raise the limit for slow calls:
File Uploads
Upload files to Pragmatiks storage programmatically:url, public_url, size, content_type, checksum, and uploaded_at.
Dependencies and Field References
A resource config points at another resource in one of two ways:- Field reference: a single output value, written in YAML as
provider,resource,name, andfield. See Resources. Dependency[T]: a whole resource, with typed access to its config and outputs in provider code.
Dependency[T]
Provider authors declare a whole-resource dependency withDependency[T]. The platform waits for the dependency to be ready before it runs the dependent’s handlers, and resolve() returns it:
Provider Authoring
The SDK also provides utilities for building providers. See Building Providers for complete documentation.Key Exports
pragma_sdk exports the building blocks of a resource: the Resource, Config, and Outputs base classes, the Provider registry, the field types, and HealthStatus.
Quick Example
Next Steps
Building Providers
Create custom providers with lifecycle methods.
Lifecycle Methods
Deep dive into on_observe, on_create, on_update, and on_delete.
API Reference
Full REST API documentation.
Error Recovery
Handle failures and retry dead letter events.