Skip to main content

Tombstone Python SDK — server-side feature flag evaluation with OpenFeature support

Project description

Tombstone Python SDK

The official Python SDK for Tombstone — production intelligence layer for feature flags.

Installation

pip install tombstone

Quick Start

from tombstone import TombstoneClient

client = TombstoneClient(
    api_url="http://localhost:8081",
    sdk_key="sdk-dev-token-change-in-prod",
    environment="development",
)
client.initialize()

enabled = client.is_enabled("my-first-flag", {"user_id": "user-123"})
print(f"Feature enabled: {enabled}")

Configuration

Parameter Type Required Default Description
api_url str Yes Base URL of your Tombstone flag-api service
sdk_key str Yes SDK authentication token (set via FLAG_API_TOKEN in infra/.env)
environment str No "production" Environment name (development, staging, production)
cache_ttl int No 30 Flag cache TTL in seconds
timeout float No 5.0 HTTP request timeout in seconds
stream_url str No None Gateway SSE URL for real-time updates (e.g. http://localhost:8080)
from tombstone import TombstoneClient

client = TombstoneClient(
    api_url="http://localhost:8081",
    sdk_key="sdk-dev-token-change-in-prod",
    environment="staging",
    cache_ttl=60,
    timeout=3.0,
    stream_url="http://localhost:8080",
)
client.initialize()

Usage

is_enabled()

Returns True if the flag is enabled for the given evaluation context.

# Simple boolean flag
enabled = client.is_enabled("my-first-flag", {"user_id": "user-123"})

# With richer context for targeting rules
enabled = client.is_enabled("checkout-v2", {
    "user_id": "user-123",
    "email": "user@example.com",
    "plan": "pro",
    "country": "US",
})

if enabled:
    show_new_checkout()
else:
    show_legacy_checkout()

get_variation()

Returns the variation value for multivariate flags. Use when you need string/number/JSON values rather than a boolean.

# String variation
theme = client.get_variation("ui-theme", {"user_id": "user-123"}, default="light")
# Returns: "light", "dark", or "high-contrast"

# JSON variation
config = client.get_variation("pricing-config", {"user_id": "user-123"}, default={})
# Returns: {"monthly": 29, "annual": 249}

# Numeric variation
limit = client.get_variation("rate-limit-tier", {"user_id": "user-123"}, default=100)

Async Support

The SDK ships an async client for use with asyncio, FastAPI, and other async frameworks.

import asyncio
from tombstone import AsyncTombstoneClient

async def main():
    client = AsyncTombstoneClient(
        api_url="http://localhost:8081",
        sdk_key="sdk-dev-token-change-in-prod",
        environment="development",
    )
    await client.initialize()

    enabled = await client.is_enabled("my-first-flag", {"user_id": "user-123"})
    print(f"Feature enabled: {enabled}")

    await client.close()

asyncio.run(main())

FastAPI integration

from contextlib import asynccontextmanager
from fastapi import FastAPI, Request
from tombstone import AsyncTombstoneClient

client: AsyncTombstoneClient

@asynccontextmanager
async def lifespan(app: FastAPI):
    global client
    client = AsyncTombstoneClient(
        api_url="http://localhost:8081",
        sdk_key="sdk-dev-token-change-in-prod",
        environment="production",
    )
    await client.initialize()
    yield
    await client.close()

app = FastAPI(lifespan=lifespan)

@app.get("/checkout")
async def checkout(request: Request, user_id: str):
    enabled = await client.is_enabled("checkout-v2", {"user_id": user_id})
    return {"checkout_version": "v2" if enabled else "v1"}

Local Development

Start the full Tombstone stack first:

git clone https://github.com/sairam0424/Tombstone.git
cd Tombstone
cp infra/.env.example infra/.env
make dev

The flag-api will be available at http://localhost:8081. The default SDK token is sdk-dev-token-change-in-prod (set via FLAG_API_TOKEN in infra/.env).

# Local development client — no changes needed
client = TombstoneClient(
    api_url="http://localhost:8081",
    sdk_key="sdk-dev-token-change-in-prod",
    environment="development",
)

Testing

Use TombstoneTestClient for unit tests — it evaluates flags locally without any network calls.

from tombstone.testing import TombstoneTestClient

def test_checkout_page():
    client = TombstoneTestClient()
    client.set_flag("checkout-v2", enabled=True)
    client.set_variation("ui-theme", "dark")

    # Your application code under test
    result = render_checkout(client)

    assert result["checkout_version"] == "v2"
    assert result["theme"] == "dark"

def test_checkout_page_disabled():
    client = TombstoneTestClient()
    client.set_flag("checkout-v2", enabled=False)

    result = render_checkout(client)

    assert result["checkout_version"] == "v1"

TombstoneTestClient implements the same interface as TombstoneClient, so you can inject it via dependency injection or monkeypatching.

Requirements

  • Python 3.10+
  • httpx (HTTP client)
  • pydantic v2 (config validation)

No other runtime dependencies.

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

tombstone_sdk-0.2.1.tar.gz (18.8 kB view details)

Uploaded Source

Built Distribution

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

tombstone_sdk-0.2.1-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tombstone_sdk-0.2.1.tar.gz
  • Upload date:
  • Size: 18.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for tombstone_sdk-0.2.1.tar.gz
Algorithm Hash digest
SHA256 7e25b08aa731531911828e126c77d796d6b98f17ac0af96b2564c3e6817ab0ea
MD5 8a251abe38f35299f1ba74787f55669a
BLAKE2b-256 424152aec81d385f0db60f27b59d68bead9cfb014eae6ff8bf013e812f5b919a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tombstone_sdk-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 13.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for tombstone_sdk-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ff9237275867642532232deca1c5a9387a28ac0b959d64593b9d0826990c102a
MD5 59172b829633593d72b6859ac8d25509
BLAKE2b-256 be98f39df2c8da1fc6e2b2a520b8e50003e9736a7c3c16cf83265ddf8f2ad4fa

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