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.0.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.0-py3-none-any.whl (21.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: coresdk-0.2.0.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.0.tar.gz
Algorithm Hash digest
SHA256 f08b69c6c0440494f1f3503f67c61dfb7bdb6ccb755dc30644c2d39231d5f7da
MD5 b57d966b62bf7e60defc1d23901ba279
BLAKE2b-256 392bae420b9c4bef4261a76b664ddfa4669212357d2d83a5fbc001256c8d4725

See more details on using hashes here.

File details

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

File metadata

  • Download URL: coresdk-0.2.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c71df449f0c8c93d21abf193e22895e0ac0fc91ea6286ad5a6d005a0da537172
MD5 f9cd4c8bf47c839e4064532cd44b9657
BLAKE2b-256 6cc59daa7ece87557feeb238b050b36d3cc6001069703af5d1166a6671e16e22

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