Skip to main content

Python SDK for the Crittora API

Project description

crittora-sdk-python

crittora-sdk-python is a typed secure-message client for the Crittora API.

It supports exactly two application workflows:

  • confidentiality only: encrypt() -> decrypt()
  • confidentiality plus authenticity: sign_encrypt() -> decrypt_verify()

This package exposes a Python-native, instance-based client designed for predictable integration in production systems:

  • explicit client construction
  • explicit credentials and auth wiring
  • transport-level timeout and retry controls
  • typed request and response objects
  • stable SDK exception classes
  • sync and async client parity

Table Of Contents

Runtime Support

  • Python 3.10 or later
  • requests for the sync client
  • optional httpx for the async client
  • optional boto3 for Cognito auth

Installation

Base install:

pip install crittora-sdk-python

Async support:

pip install 'crittora-sdk-python[async]'

Cognito support:

pip install 'crittora-sdk-python[cognito]'

Design Principles

The Python SDK is built around a few constraints that matter for SDK consumers:

  • no hidden process-global configuration is required for the primary API
  • client instances are isolated, so one process can talk to multiple environments safely
  • public Python models use snake_case
  • auth is composable rather than hard-coded into every request path
  • errors preserve transport and backend context so callers can make policy decisions
  • Python behavior should be idiomatic even when the JS SDK uses different naming

Quick Start

Sync client with bearer auth

from crittora import ApiCredentials, BearerTokenAuth, CrittoraClient, Permission

client = CrittoraClient(
    base_url="https://api.crittoraapis.com",
    credentials=ApiCredentials(
        api_key="api-key",
        access_key="access-key",
        secret_key="secret-key",
    ),
    auth=BearerTokenAuth("id-token"),
    timeout=10.0,
)

result = client.encrypt(
    "sensitive data",
    permissions=[Permission(partner_id="partner-123", actions=["read"])],
)

print(result.encrypted_data)

Scoped auth

If the same client configuration is reused across identities, create a base client and scope auth per request flow:

from crittora import BearerTokenAuth, CrittoraClient

base_client = CrittoraClient()
user_client = base_client.with_auth(BearerTokenAuth(user_id_token))

decrypted = user_client.decrypt(encrypted_data)

Async client

from crittora import AsyncCrittoraClient

async with AsyncCrittoraClient() as client:
    result = await client.encrypt("hello")

Authentication

The SDK supports two primary auth patterns:

1. Static bearer token

Use this when your application already manages a token lifecycle:

from crittora import BearerTokenAuth, CrittoraClient

client = CrittoraClient(
    auth=BearerTokenAuth(id_token),
)

2. Cognito auth provider

Use the built-in Cognito provider when the SDK should perform login and hold the returned tokens:

from crittora import CognitoAuthProvider, CognitoConfig, CrittoraClient

auth = CognitoAuthProvider(
    CognitoConfig(
        user_pool_id="us-east-1_Tmljk4Uiw",
        client_id="5cvaao4qgphfp38g433vi5e82u",
    )
)

tokens = auth.login(username="username", password="password")

client = CrittoraClient(auth=auth)

Security Note

If access_key and secret_key represent privileged backend credentials, do not expose them in untrusted client-side environments. In that model, use the SDK behind your own backend boundary.

Client Configuration

CrittoraClient accepts:

CrittoraClient(
    *,
    base_url: str = "https://api.crittoraapis.com",
    credentials: ApiCredentials | None = None,
    auth: AuthProvider | None = None,
    timeout: float = 10.0,
    retry: RetryOptions | None = None,
    headers: dict[str, str] | None = None,
    user_agent: str | None = None,
    session: requests.Session | None = None,
)

AsyncCrittoraClient accepts the same configuration, replacing session with client.

Operational guidance:

  • set base_url explicitly in non-production environments
  • keep retry counts conservative unless the backend contract explicitly supports aggressive retries
  • prefer a custom user_agent in services where request attribution matters
  • inject your own HTTP client only when you need shared lifecycle or custom transport behavior

Supported Workflows

Confidentiality only

encrypted = client.encrypt("hello")
decrypted = client.decrypt(encrypted.encrypted_data)

Confidentiality plus authenticity

envelope = client.sign_encrypt("hello")
verified = client.decrypt_verify(envelope.encrypted_data)

Lifecycle

The sync client supports explicit cleanup and context-manager usage:

with CrittoraClient() as client:
    client.encrypt("hello")

The async client supports await client.close() and async with:

async with AsyncCrittoraClient() as client:
    await client.encrypt("hello")

When you inject your own HTTP client, its lifecycle remains your responsibility. The SDK only closes clients it creates itself.

Errors

The SDK exposes one base exception and several specializations so callers can respond at the right layer:

  • ValidationError
  • AuthError
  • RequestError
  • RateLimitError
  • EncryptError
  • DecryptError

These exceptions preserve HTTP status, response details, and request identifiers where available.

Additional Documentation

Examples

Publishing

This repo is configured for PyPI Trusted Publishing through GitHub Actions.

The publish workflow is:

Before the workflow can publish, you still need to configure the matching Trusted Publisher on PyPI for this repository and workflow. See:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

crittora_sdk_python-0.1.0.tar.gz (20.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

crittora_sdk_python-0.1.0-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

File details

Details for the file crittora_sdk_python-0.1.0.tar.gz.

File metadata

  • Download URL: crittora_sdk_python-0.1.0.tar.gz
  • Upload date:
  • Size: 20.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for crittora_sdk_python-0.1.0.tar.gz
Algorithm Hash digest
SHA256 caa3bf96c593d9e695cd740a3adab3cde976b4fcfef377d918fef24776261fd3
MD5 557bd5daf72e51183d7319ee02cfccec
BLAKE2b-256 66e8fb66cea69512d35e6c55a5dc353c23090ee0bb5489b1180ec9910ab4b140

See more details on using hashes here.

File details

Details for the file crittora_sdk_python-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for crittora_sdk_python-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 347a30bd9e95a34276df61056cac45c883ee84d229bb842dd70847efc9b88379
MD5 b4bb802a59807f3ec34c6a6376dbdf27
BLAKE2b-256 644d5e488cf1f498ce5ccb3f5fa0521ee50ac3771956b87a05927c6a28ee5a15

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page