Skip to main content

Turnkey HTTP

HTTP client for the Turnkey API with auto-generated methods from the OpenAPI specification.

Installation

pip install turnkey-http

Or install from the repository in editable mode:

pip install -e packages/http

Usage

from turnkey_http import TurnkeyClient
from turnkey_api_key_stamper import ApiKeyStamper, ApiKeyStamperConfig

# Initialize the stamper
config = ApiKeyStamperConfig(
    api_public_key="your-api-public-key",
    api_private_key="your-api-private-key"
)
stamper = ApiKeyStamper(config)

# Create the HTTP client
client = TurnkeyClient(
    base_url="https://api.turnkey.com",
    stamper=stamper,
    organization_id="your-org-id"
)

# Make API calls with typed methods
response = client.get_whoami()
print(response)

Handling activity outcomes

Activity methods poll until the activity finishes. If it does not complete, they raise an error. TurnkeyActivityConsensusNeededError means the activity needs more approvals. TurnkeyActivityAuthenticatorsNeededError means it needs authenticator approval. TurnkeyActivityError means it failed, was rejected, or was still pending when polling stopped. These errors carry activity_id, activity_status, activity_type, and failure. Catch the subclasses first, because they extend TurnkeyActivityError.

Consensus-needed and authenticators-needed each stop the normal activity poll. Pass a PollingConfig as consensus_polling or mfa_polling to keep polling that status. The MFA interval doubles on each attempt, up to 5 seconds. The consensus interval stays fixed. Omit a config to raise that status's error immediately. A timeout raises the same error. Use activity_id with get_activity after the missing approvals are in place.

from turnkey_http import PollingConfig, TurnkeyClient
from turnkey_sdk_types import (
    TurnkeyActivityAuthenticatorsNeededError,
    TurnkeyActivityConsensusNeededError,
    TurnkeyActivityError,
)

client = TurnkeyClient(
    base_url="https://api.turnkey.com",
    stamper=stamper,
    organization_id="your-org-id",
    consensus_polling=PollingConfig(interval_ms=500, timeout_ms=30_000),
    mfa_polling=PollingConfig(interval_ms=500, timeout_ms=30_000),
)

try:
    response = ...  # any activity method
except TurnkeyActivityConsensusNeededError as err:
    activity_id = err.activity_id
except TurnkeyActivityAuthenticatorsNeededError as err:
    activity_id = err.activity_id
except TurnkeyActivityError as err:
    print(err.activity_status, err.failure)

Faster imports (optional)

Set TURNKEY_SDK_DEFER_BUILD=1 to build each model on first use instead of at import. Requires turnkey-sdk-types 0.3.0+ and Pydantic 2.5+. It's read once at first import, so set it in your environment or before any Turnkey import.

When enabled, each model's first use is a little slower, and a process that uses nearly every model can use more memory than the default. On Pydantic 2.5–2.10, call Model.model_rebuild() before inspecting model_fields[...].annotation.

Code Generation

This package uses code generation to create HTTP client methods from the OpenAPI specification located in schema/public_api.swagger.json.

Generate Client

To regenerate the HTTP client:

cd packages/http
python3 scripts/generate.py

The generator automatically formats code with ruff.

Development Setup

Install with dev dependencies:

pip install -e ".[dev]"

Structure

http/
├── src/
│   └── turnkey_http/
│       ├── __init__.py
│       └── generated/         # Auto-generated client (do not edit manually)
├── scripts/
│   └── generate.py           # Code generation script
├── tests/                    # Test suite
├── pyproject.toml
└── README.md

Dependencies

  • Python >= 3.8
  • requests >= 2.31.0
  • turnkey-api-key-stamper
  • turnkey-sdk-types

Development

The generated client is created from the OpenAPI specification with:

  • Typed methods for each API endpoint
  • Automatic request signing via stamper integration
  • Type hints using types from turnkey-sdk-types

Important: Never edit files in src/turnkey_http/generated/ manually. They will be overwritten on the next generation run.

Metadata

Release files for turnkey-http 0.2.3

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

Source distribution (sdist)

Source distribution for turnkey-http 0.2.3
File Size Uploaded Provenance Actions
turnkey_http-0.2.3.tar.gz 31.4 kB With provenance Details for turnkey_http-0.2.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for turnkey-http 0.2.3
File Interpreter ABI Platform Actions
turnkey_http-0.2.3-py3-none-any.whl Python 3 none any Details for turnkey_http-0.2.3-py3-none-any.whl

Total release size: 55.6 kB

Release files / turnkey_http-0.2.3.tar.gz

Download URL turnkey_http-0.2.3.tar.gz
Size 31.4 kB
Tags Source
SHA-256 checksum
How to use checksums
82f84731c58a78ca1c3309349f6215219d20f8bed0f6bc77b123435e1c1a6a21
BLAKE2b-256 checksum
How to use checksums
45b49ffb4d7b24e3fa82cb8f23717c88aae03623099e0cef75cc9e9310504ab1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Release files / turnkey_http-0.2.3-py3-none-any.whl

Download URL turnkey_http-0.2.3-py3-none-any.whl
Size 24.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4bc0a3c9a992896e50e4b0555b7380651df6e614b3550097466e5c5ece461e07
BLAKE2b-256 checksum
How to use checksums
605bfcb84d24cbd378e4236160459731585a6a91d371c68378db13ce4a40afcc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Security for turnkey-http 0.2.3

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for turnkey_http-0.2.3.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

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.

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