Skip to main content

CoreSDK — auth, policy, observability. One import.

Project description

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

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

coresdk-0.2.1.tar.gz (23.4 kB view details)

Uploaded Source

Built Distribution

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

coresdk-0.2.1-py3-none-any.whl (21.6 kB view details)

Uploaded Python 3

File details

Details for the file coresdk-0.2.1.tar.gz.

File metadata

  • Download URL: coresdk-0.2.1.tar.gz
  • Upload date:
  • Size: 23.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for coresdk-0.2.1.tar.gz
Algorithm Hash digest
SHA256 bc3662553f31f799453f37e5434a361bd427034be22651e78074b5311d0dd24c
MD5 b565ac64afa3385988827b7df50bd7b3
BLAKE2b-256 ad622c8d2450c58beee920f0a503b4e1cfcffa5eaaa365a280970a304711c275

See more details on using hashes here.

File details

Details for the file coresdk-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: coresdk-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 21.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for coresdk-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4a741ef985dab978b3c28ab447ab51e0aed6f547df1de0ffd3ea7d52f81db35a
MD5 6417aa737de508a950c2ec91940e4e21
BLAKE2b-256 693d5739ab066bc96cc28699486a814701b8b2db015a2cf323b22ab32959899d

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