Forkcast for Python
The Python SDK for Forkcast, the self-hosted A/B testing and feature flag tool. Use it in FastAPI, Flask, Django, scripts and workers.
- Same buckets as the JavaScript SDK. A user gets the same treatment from your Python API and your React frontend.
- Local evaluation. Config is fetched once and kept fresh in the background, so every
get_treatment()is pure hashing with no network call. - Works offline. If the server is unreachable, everything falls back to
C(control) and your app never crashes. - No dependencies. Only the Python standard library. FastAPI and Flask helpers are optional.
- Typed (
py.typed). Python 3.10+.
pip install forkcast-sdk
You import it as forkcast.
Quick start
-
Start a Forkcast server and dashboard (needs Node.js 18+):
npx forkcast start
Open http://localhost:4400, create an experiment (say
new-checkout) and copy a client key from Environments. -
Ask for a treatment in Python:
from forkcast import Forkcast forkcast = Forkcast( api_url="http://localhost:4400", client_key="fc_prod_...", # from the dashboard ) fc = forkcast.for_user({"id": "user-42", "country": "IN", "plan": "pro"}) if fc.get_treatment("new-checkout") == "T1": show_one_click_checkout() else: # "C", the control show_cart_page() fc.track("purchase", value=49.99) # conversion for the results page
-
Change traffic, targeting or the kill switch in the dashboard. Python picks it up within 30 seconds (or instantly with
realtime=True). There's no redeploy.
FastAPI
from fastapi import Depends, FastAPI, Request
from forkcast import Forkcast, ScopedForkcast
from forkcast.integrations.fastapi import forkcast_dependency, forkcast_lifespan
forkcast = Forkcast(api_url="http://localhost:4400", client_key="fc_prod_...")
def current_user(request: Request) -> dict:
return {"id": request.headers.get("x-user-id"), "country": request.headers.get("cf-ipcountry")}
get_forkcast = forkcast_dependency(forkcast, current_user)
app = FastAPI(lifespan=forkcast_lifespan(forkcast)) # flushes events on shutdown
@app.get("/checkout")
def checkout(fc: ScopedForkcast = Depends(get_forkcast)):
return {"one_click": fc.get_treatment("new-checkout") == "T1"}
Flask
from flask import Flask, request, session
from forkcast import Forkcast
from forkcast.integrations.flask import FlaskForkcast, current_forkcast
app = Flask(__name__)
forkcast = Forkcast(api_url="http://localhost:4400", client_key="fc_prod_...")
FlaskForkcast(
app,
forkcast,
get_user=lambda: {
"id": session.get("user_id"),
"country": request.headers.get("CF-IPCountry"),
},
)
@app.get("/checkout")
def checkout():
if current_forkcast.get_treatment("new-checkout") == "T1":
return "one-click checkout"
return "cart page"
In Jinja templates you can write {% if forkcast.is_enabled("dark-mode") %}.
More
- Full Python guide, covering every option and method, Django, gunicorn, testing and local mode: docs/python.md
- Concepts (C/T1/T2, traffic, targeting, environments): docs/concepts.md
- Main project, JavaScript SDK and dashboard: github.com/Alik-Agarwala/forkcast
MIT licensed.
Metadata
Release files for forkcast-sdk 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| forkcast_sdk-0.1.0.tar.gz | 61.1 kB | With provenance | Details for forkcast_sdk-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| forkcast_sdk-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for forkcast_sdk-0.1.0-py3-none-any.whl |
Total release size: 85.0 kB
Release files / forkcast_sdk-0.1.0.tar.gz
| Download URL | forkcast_sdk-0.1.0.tar.gz |
|---|---|
| Size | 61.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b81f599888cb9541de7b8f0352f92e7da27e107709543ab0b656f52258e06015
|
|
BLAKE2b-256 checksum How to use checksums |
3afcb7a375acfbfd85bedb173d25d5d8ef8c57df1e22750859e98af42e071648
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.
Transparency logRelease files / forkcast_sdk-0.1.0-py3-none-any.whl
| Download URL | forkcast_sdk-0.1.0-py3-none-any.whl |
|---|---|
| Size | 23.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c9797c254054a80e4bed968221ecd9e45f6786c2b285bdc3d4fb90b0423d5cdf
|
|
BLAKE2b-256 checksum How to use checksums |
673249232fe48a49c3aa661d26a9f8f1dbb017dbfa7a3707e89d5f78d0a47684
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.
Transparency logSecurity for forkcast-sdk 0.1.0
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for forkcast_sdk-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.
Transparency logA 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.