Python SDK for the Pragmatiks platform
Project description
Pragmatiks SDK
Python SDK for building providers and interacting with the Pragmatiks platform.
Installation
uv add pragmatiks-sdk
Quick Start
HTTP Clients
Interact with the Pragma API using sync or async clients:
from pragma_sdk import PragmaClient, AsyncPragmaClient, Resource
# Synchronous client
with PragmaClient() as client:
resources = client.list_resources(provider="postgres")
db = client.get_resource("postgres", "database", "my-db")
resource = client.apply_resource(
Resource(
provider="postgres",
resource="database",
name="my-db",
config={"name": "analytics", "size_gb": 100}
)
)
client.delete_resource("postgres", "database", "my-db")
# Asynchronous client
async with AsyncPragmaClient() as client:
resources = await client.list_resources(provider="postgres")
db = await client.get_resource("postgres", "database", "my-db")
await client.delete_resource("postgres", "database", "my-db")
Provider Authoring
Build providers that manage infrastructure resources with type-safe configuration and outputs.
Basic Provider
from pragma_sdk import Provider, Resource, Config, Outputs, Field
# Create a provider namespace
postgres = Provider(name="postgres")
# Define configuration schema
class DatabaseConfig(Config):
db_name: Field[str]
size_gb: Field[int] = 10
owner: Field[str] = "postgres"
# Define output schema
class DatabaseOutputs(Outputs):
connection_url: str
created_at: str
# Implement resource lifecycle
@postgres.resource("database")
class Database(Resource[DatabaseConfig, DatabaseOutputs]):
async def on_create(self) -> DatabaseOutputs:
# Create the database
return DatabaseOutputs(
connection_url=f"postgres://localhost/{self.config.db_name}",
created_at="2025-01-01T00:00:00Z"
)
async def on_update(self, previous_config: DatabaseConfig) -> DatabaseOutputs:
# Update the database if config changed
if previous_config.size_gb != self.config.size_gb:
# Resize database
pass
return self.outputs # type: ignore
async def on_delete(self) -> None:
# Delete the database
pass
Resource Lifecycle
Resources follow a 5-state lifecycle:
DRAFT → PENDING (commit)
PENDING → PROCESSING (provider picks up)
PROCESSING → READY (success) | FAILED (error)
READY/FAILED → PENDING (update/retry)
READY/FAILED → DRAFT (uncommit)
Field References
Reference outputs from other resources:
from pragma_sdk import FieldReference
app_config = AppConfig(
name="my-app",
# Reference database URL instead of hardcoding
database_url=FieldReference(
provider="postgres",
resource="database",
name="my-db",
field="outputs.connection_url"
)
)
Testing Providers
Use ProviderHarness to test lifecycle methods locally without platform infrastructure:
from pragma_sdk.provider import ProviderHarness
async def test_database_creation():
harness = ProviderHarness()
# Test on_create
result = await harness.invoke_create(
Database,
name="test-db",
config=DatabaseConfig(db_name="test-db", size_gb=10)
)
assert result.success
assert result.outputs.connection_url == "postgres://localhost/test-db"
# Test on_update
result = await harness.invoke_update(
Database,
name="test-db",
config=DatabaseConfig(db_name="test-db", size_gb=20),
previous_config=DatabaseConfig(db_name="test-db", size_gb=10),
current_outputs=result.outputs
)
assert result.success
# Test on_delete
result = await harness.invoke_delete(
Database,
name="test-db",
config=DatabaseConfig(db_name="test-db")
)
assert result.success
Authentication
Credentials are discovered automatically in this order:
- Explicit
auth_tokenparameter - Context-specific environment variable:
PRAGMA_AUTH_TOKEN_<CONTEXT> - Generic environment variable:
PRAGMA_AUTH_TOKEN - Credentials file:
~/.config/pragma/credentials
# Auto-discover from environment or credentials file
client = PragmaClient()
# Explicit token
client = PragmaClient(auth_token="eyJhbGc...")
# Specific context
client = PragmaClient(context="production")
# Require authentication (fail if no token found)
client = PragmaClient(context="production", require_auth=True)
Environment Variables
# Generic token (all contexts)
export PRAGMA_AUTH_TOKEN=sk_test_...
# Context-specific token
export PRAGMA_AUTH_TOKEN_PRODUCTION=sk_prod_...
export PRAGMA_CONTEXT=production
API Reference
HTTP Clients
Both PragmaClient and AsyncPragmaClient provide:
is_healthy()- Check API healthlist_resources(provider, resource, tags)- List resourcesget_resource(provider, resource, name)- Get a resourceapply_resource(resource)- Create or update a resourcedelete_resource(provider, resource, name)- Delete a resourceregister_resource(provider, resource, schema, description, tags)- Register a resource typeunregister_resource(provider, resource)- Unregister a resource type
Provider Classes
-
Provider(name)- Provider namespace@provider.resource(name)- Decorator to register resources
-
Resource[ConfigT, OutputsT]- Base class for resourceson_create()- Handle resource creationon_update(previous_config)- Handle resource updateson_delete()- Handle resource deletion
-
Config- Base class for resource configuration -
Outputs- Base class for resource outputs -
Field[T]- Type alias forT | FieldReference
Testing
ProviderHarness- Local test harnessinvoke_create(resource_class, name, config, tags)- Test on_createinvoke_update(resource_class, name, config, previous_config, current_outputs, tags)- Test on_updateinvoke_delete(resource_class, name, config, current_outputs, tags)- Test on_deleteevents- List of lifecycle eventsresults- List of lifecycle resultsclear()- Clear event and result history
Development
# Run tests
pytest
# Format code
ruff format
# Lint
ruff check
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pragmatiks_sdk-0.3.1.tar.gz.
File metadata
- Download URL: pragmatiks_sdk-0.3.1.tar.gz
- Upload date:
- Size: 13.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cc2af1e1b70c4d5bbc1068780cdc5b1e12751e09c252ef1657366d95f9142e50
|
|
| MD5 |
e730278dc5214d35ba946fc0aa1daaeb
|
|
| BLAKE2b-256 |
4dbfb680e4ab75e22ee094039023ca279e7bb816d2cf45d101bf6c2fe2b33333
|
Provenance
The following attestation bundles were made for pragmatiks_sdk-0.3.1.tar.gz:
Publisher:
publish.yaml on pragmatiks/sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pragmatiks_sdk-0.3.1.tar.gz -
Subject digest:
cc2af1e1b70c4d5bbc1068780cdc5b1e12751e09c252ef1657366d95f9142e50 - Sigstore transparency entry: 816038317
- Sigstore integration time:
-
Permalink:
pragmatiks/sdk@514d9a0713fc64d145633faf9b50846dc46e15e5 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/pragmatiks
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@514d9a0713fc64d145633faf9b50846dc46e15e5 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pragmatiks_sdk-0.3.1-py3-none-any.whl.
File metadata
- Download URL: pragmatiks_sdk-0.3.1-py3-none-any.whl
- Upload date:
- Size: 17.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eaa90dc71cf1ce293e8d8d13df9416475c0da006624a9e9bba6af3c48e5b5393
|
|
| MD5 |
12fa9ee77a982f5b184df2ce022e4672
|
|
| BLAKE2b-256 |
f83c5ada0b202849b6c21c80d1595350abb15e8c0f29a9ac891f579eeac5a524
|
Provenance
The following attestation bundles were made for pragmatiks_sdk-0.3.1-py3-none-any.whl:
Publisher:
publish.yaml on pragmatiks/sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pragmatiks_sdk-0.3.1-py3-none-any.whl -
Subject digest:
eaa90dc71cf1ce293e8d8d13df9416475c0da006624a9e9bba6af3c48e5b5393 - Sigstore transparency entry: 816038357
- Sigstore integration time:
-
Permalink:
pragmatiks/sdk@514d9a0713fc64d145633faf9b50846dc46e15e5 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/pragmatiks
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@514d9a0713fc64d145633faf9b50846dc46e15e5 -
Trigger Event:
push
-
Statement type: