Skip to main content

CoreSDK Python

CI PyPI Python License

Auth, policy enforcement, observability, and multi-tenancy for Python services — one import, backed by the CoreSDK sidecar.

Install

pip install coresdk           # core only
pip install "coresdk[fastapi]"  # + FastAPI middleware
pip install "coresdk[flask]"    # + Flask middleware

Quick start

from coresdk import CoreSDKClient, SDKConfig

sdk = CoreSDKClient(SDKConfig(
    sidecar_addr="[::1]:50051",
    tenant_id="my-org",
    service_name="my-api",
))

# Validate a JWT (calls sidecar over gRPC)
claims = sdk.validate_token("Bearer eyJ...")
print(claims["sub"])

# Evaluate a Rego policy
allowed = sdk.evaluate_policy("data.authz.allow", {
    "subject": claims["sub"],
    "action": "read",
    "resource": "reports/q4",
})

Authorize requests

from coresdk import SDK

sdk = SDK.from_env()

# Authorize a token against a resource + action
decision = sdk.authorize("eyJ...", action="read", resource="/orders")
if decision.allowed:
    print(f"Allowed for {decision.claims['sub']}")
else:
    print(f"Denied: {decision.reason}")

FastAPI middleware

from coresdk.middleware.fastapi import CoreSDKMiddleware

app.add_middleware(CoreSDKMiddleware, sdk=sdk_adapter,
                   exclude_paths=["/healthz"])

All routes protected by default. Claims available via request.state.coresdk_user.

Flask middleware

from coresdk.middleware.flask import CoreSDKMiddleware

CoreSDKMiddleware(app, sdk=sdk_adapter, exclude_paths=["/healthz"])

Claims available via flask.g.claims.

PII-safe tracing

from coresdk.tracing.decorator import trace

@trace(intent="list-orders")
async def list_orders(tenant_id: str) -> list:
    ...

Secrets and PII are redacted from all span attributes before export. Set OTEL_EXPORTER_OTLP_ENDPOINT to send traces to your collector.

Config from environment

Variable Default Description
CORESDK_SIDECAR_ADDR [::1]:50051 gRPC address of the sidecar
CORESDK_TENANT_ID — Default tenant slug
CORESDK_SERVICE_NAME — Service name in traces
CORESDK_FAIL_MODE open open or closed on sidecar error
OTEL_EXPORTER_OTLP_ENDPOINT — OTLP trace exporter endpoint

mTLS

To enable mutual TLS between your application and the sidecar, set all three TLS environment variables:

Variable Description
CORESDK_TLS_CERT Path to the client certificate (PEM)
CORESDK_TLS_KEY Path to the client private key (PEM)
CORESDK_TLS_CA Path to the CA certificate (PEM)
export CORESDK_TLS_CERT=/path/to/client.crt
export CORESDK_TLS_KEY=/path/to/client.key
export CORESDK_TLS_CA=/path/to/ca.crt

When all three are present, the SDK configures grpcio with TLS 1.3 mutual authentication automatically. See the core-sdk README for certificate generation instructions.

Examples

Full working projects in coresdk-dev/examples:

Sidecar

Download the sidecar binary from coresdk-dev/core releases:

# macOS (Apple Silicon)
curl -LO https://github.com/coresdk-dev/core/releases/latest/download/coresdk-sidecar-aarch64-apple-darwin.tar.gz
tar xf coresdk-sidecar-aarch64-apple-darwin.tar.gz
./coresdk-sidecar

Or run via Docker:

docker run -p 50051:50051 ghcr.io/coresdk-dev/sidecar:latest

Development

git clone git@github.com:coresdk-dev/sdk-python.git && cd sdk-python
pip install -e ".[dev,fastapi,flask]"
pytest tests/ -v

License

Apache-2.0 — see LICENSE

Metadata

Release files for coresdk 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 coresdk 0.2.1
File Size Uploaded Provenance Actions
coresdk-0.2.1.tar.gz 23.4 kB Without provenance Details for coresdk-0.2.1.tar.gz

Built distribution (wheel)

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

Total release size: 45.0 kB

Release files / coresdk-0.2.1.tar.gz

Download URL coresdk-0.2.1.tar.gz
Size 23.4 kB
Tags Source
SHA-256 checksum
How to use checksums
bc3662553f31f799453f37e5434a361bd427034be22651e78074b5311d0dd24c
BLAKE2b-256 checksum
How to use checksums
ad622c8d2450c58beee920f0a503b4e1cfcffa5eaaa365a280970a304711c275
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

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

Download URL coresdk-0.2.1-py3-none-any.whl
Size 21.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4a741ef985dab978b3c28ab447ab51e0aed6f547df1de0ffd3ea7d52f81db35a
BLAKE2b-256 checksum
How to use checksums
693d5739ab066bc96cc28699486a814701b8b2db015a2cf323b22ab32959899d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Security for coresdk 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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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