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)

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.1

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.1
File Size Uploaded Provenance Actions
turnkey_http-0.2.1.tar.gz 30.4 kB With provenance Details for turnkey_http-0.2.1.tar.gz

Built distribution (wheel)

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

Total release size: 54.3 kB

Release files / turnkey_http-0.2.1.tar.gz

Download URL turnkey_http-0.2.1.tar.gz
Size 30.4 kB
Tags Source
SHA-256 checksum
How to use checksums
277f3d4434880a8d0ed7de773c74c1f6e8cf3ab7cf09f539a9404e52176d643d
BLAKE2b-256 checksum
How to use checksums
686be75119acee6baa1106700c31c418e8b3ff242c83de450395a34f43f64c3e
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 Oct 20, 2026.

Transparency log

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

Download URL turnkey_http-0.2.1-py3-none-any.whl
Size 23.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
29907c015e47f5a364bef281ecae11ef02ba252a645a30936ab64d8d2c76e7fe
BLAKE2b-256 checksum
How to use checksums
6a42c0bf81539350f911e9244c964608df9bc707c3afcee117e8c1f70a95c971
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 Oct 20, 2026.

Transparency log

Security for turnkey-http 0.2.1

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.1.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 Oct 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