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.1.0.tar.gz (11.9 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.1.0-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tombstone_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for tombstone_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7d0242838328ee93037523b4ae8ab2efbbc8ad2ada97f14aada3c8ee2f59e208
MD5 318b6fb1d472add7868fe5447f362d86
BLAKE2b-256 9f2a2decc56eb449596c21ab71202ff9e0a0525a2c63792e96072e63a74e5e36

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tombstone_sdk-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for tombstone_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 38cb43f591d1c5382881bcd8bdc894625c8aa84d5c8e3dc682f7ed687a12c78b
MD5 ce3770b991efee9b0a3ec26a76646fae
BLAKE2b-256 a6e255c92ab6226242de15655adb4e346b30a60a2778a022d59bf245246e8f57

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