Skip to main content

cofide-sdk-python

Python SDK for workloads that authenticate with SPIFFE or platform identity (e.g. AWS) and use Credex to exchange credentials. Its entry point, WorkloadIdentityManager, offers three things:

  • ID tokens prove the workload's identity: the platform-native one with await workload_identity_manager.id_token(audience), or a JWT-SVID with await workload_identity_manager.spiffe_id_token(audience).
  • Access tokens from Credex access a resource, for the workload itself or on a caller's behalf: await workload_identity_manager.access_token(audience, scope).
  • Mutual TLS connects workloads, each presenting its X.509-SVID and authorizing the other by SPIFFE ID: workload_identity_manager.mtls_http_client(server_id=...).

Optional adapters connect these to httpx2, LangChain, MCP, uvicorn, Anthropic, and AWS Bedrock. The building blocks behind WorkloadIdentityManager (identity token sources, RFC 8693 token exchange, SPIFFE mTLS) are in submodules for the cases it doesn't cover.

Preview. This SDK is in preview: the API may change between releases without notice.

Features

  • Identity token sources: JWT-SVIDs from the SPIFFE Workload API, or platform identity tokens (AWS STS, OIDC) federated through Credex.
  • Access tokens: RFC 8693 exchange against Credex for access tokens to OAuth-protected APIs, including delegation on a caller's behalf.
  • HTTP authentication: httpx2 authentication that fetches a valid token for every request.
  • Mutual TLS: httpx2 clients, ssl.SSLContexts, and uvicorn servers that present the workload's X.509-SVID, rotate it automatically, and authorize peers by SPIFFE ID.
  • Integrations: Anthropic and AWS workload identity federation (WIF), LangChain chat models for Anthropic and Bedrock, and authenticated LangChain MCP connections.

Usage

import asyncio

import httpx2
from cofide_sdk import WorkloadIdentityManager


async def main() -> None:
    # Configured from the environment.
    async with WorkloadIdentityManager() as workload_identity_manager:
        # Prove the workload's identity to a service that accepts it directly.
        auth = workload_identity_manager.id_token_auth("https://proxy.example.com")
        async with httpx2.AsyncClient(auth=auth) as http:
            await http.get("https://proxy.example.com/things")

        # Access an OAuth-protected API with a token from Credex.
        auth = workload_identity_manager.access_token_auth(
            "https://api.example.com", ["things:read"],
        )
        async with httpx2.AsyncClient(auth=auth) as http:
            await http.get("https://api.example.com/things")

        # Call another workload over mutual TLS.
        async with workload_identity_manager.mtls_http_client(
            server_id="spiffe://example.org/ledger",
        ) as http:
            await http.get("https://ledger:8443/accounts")


asyncio.run(main())

Install

Requires Python 3.12 or later.

pip install cofide-sdk

Optional extras, e.g. pip install "cofide-sdk[aws]":

Extra Adds
aws boto3, for the aws_sts identity token source and AWS WIF support
anthropic Anthropic SDK, for Anthropic WIF support
langchain-anthropic Anthropic SDK and langchain-anthropic, for the chat_anthropic LangChain adapter
langchain-aws boto3 and langchain-aws, for the chat_bedrock LangChain adapter

MCP connections need no extra; install langchain[mcp] to use them with LangChain's MCP adapter.

Configuration

WorkloadIdentityManager() loads its configuration from environment variables with WorkloadIdentityConfig.from_env(). Alternatively, pass a WorkloadIdentityConfig built directly; the environment is then not read.

Variable WorkloadIdentityConfig field Purpose
COFIDE_IDENTITY_TOKEN_SOURCE identity_token_source spiffe (default), aws_sts, or static; see below
COFIDE_TOKEN_ENDPOINT token_endpoint Credex OAuth token endpoint, e.g. https://credex.example.com/token
COFIDE_CREDEX_URL credex_url Default ID token audience for integrations that take an optional one, e.g. a Cofide-protected proxy
COFIDE_BEARER_TOKEN bearer_token Bearer token for the static source; not recommended
SPIFFE_ENDPOINT_SOCKET socket_path Workload API socket, for the spiffe source and mutual TLS; default unix:///tmp/spire-agent/public/api.sock
COFIDE_SPIFFE_ID spiffe_id The workload's SPIFFE ID, for ID tokens from the spiffe source and for mutual TLS, when the Workload API issues several; default: the Workload API chooses
COFIDE_WORKLOAD_API_TIMEOUT workload_api_timeout Workload API timeout in seconds; default 5
ANTHROPIC_WIF_FEDERATION_RULE_ID, ANTHROPIC_WIF_ORGANIZATION_ID, ANTHROPIC_WIF_SERVICE_ACCOUNT_ID anthropic Enable Anthropic WIF; all three are required together
ANTHROPIC_WIF_WORKSPACE_ID anthropic.workspace_id Optional Anthropic workspace
ANTHROPIC_WIF_AUDIENCE anthropic.audience JWT audience for Anthropic; default https://api.anthropic.com
AWS_REGION, AWS_DEFAULT_REGION aws_sts_region, aws.region Region for the aws_sts STS client (unset: boto3's default) and for AWS WIF (unset: us-east-1)
AWS_WIF_ROLE_ARN aws.role_arn Enable AWS WIF with this role
AWS_WIF_AUDIENCE aws.audience JWT audience for AWS WIF; default sts.amazonaws.com
AWS_WIF_ROLE_SESSION_NAME aws.session_name AWS WIF role session name; default cofide-workload

identity_token_source selects where the workload's ID tokens come from:

Source Behavior
spiffe (default) Requires the Workload API socket
aws_sts Requires AWS identity (boto3's standard credential chain); ID tokens are STS web identity tokens, and JWT-SVIDs (spiffe_id_token()) are issued by Credex at token_endpoint in exchange for them
static Requires bearer_token, presented as the ID token for any audience; not recommended

To use another identity token source, pass it to WorkloadIdentityManager(config, identity_token_source=...).

Licence

Copyright 2026 Cofide Limited.

Licensed under the Apache License, Version 2.0.

Metadata

Release files for cofide-sdk 0.1.0

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

Source distribution (sdist)

Source distribution for cofide-sdk 0.1.0
File Size Uploaded Provenance Actions
cofide_sdk-0.1.0.tar.gz 35.6 kB With provenance Details for cofide_sdk-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cofide-sdk 0.1.0
File Interpreter ABI Platform Actions
cofide_sdk-0.1.0-py3-none-any.whl Python 3 none any Details for cofide_sdk-0.1.0-py3-none-any.whl

Total release size: 77.4 kB

Release files / cofide_sdk-0.1.0.tar.gz

Download URL cofide_sdk-0.1.0.tar.gz
Size 35.6 kB
Tags Source
SHA-256 checksum
How to use checksums
01f81ff3421d4502d0a806ef7dd449ceb12b2002aee29a0e2fb8dee1842f6b60
BLAKE2b-256 checksum
How to use checksums
0814bd1cc35e5f3a610dbf329640f3f6514ab48073415bdf2709ec23f22dee38
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 18, 2026.

Transparency log

Release files / cofide_sdk-0.1.0-py3-none-any.whl

Download URL cofide_sdk-0.1.0-py3-none-any.whl
Size 41.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7e9cb6d48b4b6755a0e012b0b3577f867c4d0d1386d4d973bef4880e12e6b8a3
BLAKE2b-256 checksum
How to use checksums
a0529b9cf610c7cadefee5a2e1279a5007cac0dbdd4661dcf320d99be6ef514b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 18, 2026.

Transparency log

Security for cofide-sdk 0.1.0

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 cofide_sdk-0.1.0.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 18, 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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

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