Skip to main content

gittins

An opinionated, highly optimised contextual bandit engine.

  • Online by nature. Learns one observation at a time, in O(1) work and fixed memory, as long as open decisions are regularly resolved.
  • Non-stationarity is expected. The engine adapts as the relationship between context and feedback drifts, and never learns anything it cannot eventually unlearn.
  • Dynamic actions and context. The candidate set can change on every call; you never declare the number of actions up front.
  • Safe reward handling. Rewards may arrive late or never. Constructing invalid training data is made hard by design.
  • Speed and determinism. Bit-identical results across platforms and language bindings, enforced by a golden test corpus.
  • Bring your own model. Swap in your own scoring or exploration and inherit everything else.

Full documentation and user guide: docs.getgittins.dev

Install

pip install gittins

Usage

The state is an opaque handle updated in place — calls return only their result, and every alias of the handle observes the current state. Persist it with serialize, which returns one plain string.

import time
import gittins

state = gittins.create(bits=8, horizon=3600.0)  # model size, seconds to resolve

candidates = [
    ("banner-sale", {"discount": 0.2}),
    ("banner-new", {"discount": 0.0}),
    ("banner-plain", {}),
]
context = {"device": "mobile", "hour": 14}

record = gittins.decide(state, context, candidates, time.time(), "web-1")
arm_id = candidates[record.chosen][0]
# ... your code: act on the choice, then report the outcome

gittins.learn(state, record.decision_id, 1.0, time.time())
gittins.expire(state, time.time())  # resolve anything past its horizon

open("bandit.txt", "w").write(gittins.serialize(state))

Feature values are typed by what you pass: strings are categorical, ints, floats and bools numeric, None absent. Anything else raises ValueError naming the feature.

Bringing your own model

decide takes optional score and explore callbacks, and learn/expire take train. Each crosses the Python/Rust boundary once per call — with all candidates, all estimates, or the one resolved record — never once per candidate, so the one boundary crossing per decision is preserved.

Offline policy evaluation

log_line renders a decision record or resolution as one canonical experience-log line. Append it verbatim; it is exactly what the gittins CLI's verify / eval / sweep / replay consume.

with open("decisions.jsonl", "a") as log:
    log.write(gittins.log_line(record) + "\n")

API

Function Purpose
create(bits, horizon, default_reward=0.0, epsilon=..., forgetfulness=...) New state
decide(state, context, candidates, t, salt, score=None, explore=None) Choose; returns a DecisionRecord
learn(state, decision_id, reward, t, train=None) Resolve one decision; returns a Resolution or None
expire(state, t, train=None) Resolve everything past its horizon
serialize(state) / deserialize(text) State as one plain string
model_bits(state) The model's size in bits
log_line(record_or_resolution) One canonical experience-log line

License

MIT. Named after John Gittins, whose index (1974) established that exploration has a precise, computable value.

Metadata

Release files for gittins 1.0.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gittins 1.0.7
File Size Uploaded Provenance
gittins-1.0.7.tar.gz 52.1 kB With provenance Details

Built distributions (wheels)

Table of built distributions (wheels) for gittins 1.0.7
File
gittins-1.0.7-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details
gittins-1.0.7-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-64 Details
gittins-1.0.7-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64 Details
gittins-1.0.7-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details
gittins-1.0.7-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details

Total release size: 1.4 MB

Release files / gittins-1.0.7.tar.gz

Download URL gittins-1.0.7.tar.gz
Size 52.1 kB
Tags Source
SHA-256 checksum
How to use checksums
5101d73297f5aea2a98cd3ad75cd6ef0e91953af4710aabc74df8c4b2acac558
BLAKE2b-256 checksum
How to use checksums
bcfd331021fe590ab7d38ac6a2f0673c7b8e1b68b5e8b1a8851da3d1c5631dad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 6, 2026.

Transparency log

Release files / gittins-1.0.7-cp310-abi3-win_amd64.whl

Download URL gittins-1.0.7-cp310-abi3-win_amd64.whl
Size 178.0 kB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
d73cd74d6879deba024c4e50174030949c642f5569bf288db81d799661d9f63e
BLAKE2b-256 checksum
How to use checksums
6b74627eaa3af322bc55d3b7a499ca7f425d700e24e77a713df4297440247fb7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 6, 2026.

Transparency log

Release files / gittins-1.0.7-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL gittins-1.0.7-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 324.2 kB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
bb6401093d84ae2bfca448b3ac293b969d904be8069db1fcc5197a09f723798e
BLAKE2b-256 checksum
How to use checksums
dc282249abf9e5edd3bd8f066a65c3f2a374a153eb33cd625819bffeea158a40
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 6, 2026.

Transparency log

Release files / gittins-1.0.7-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL gittins-1.0.7-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 317.8 kB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
7b83e967500be99ce9b7791b0bf5cf9103a8acb08e2f486a86b49ad6cacf05ca
BLAKE2b-256 checksum
How to use checksums
a1bb32110b6ce30e2b8da052d18821f8c9a5eded56967a7e77f6b319f0628c26
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 6, 2026.

Transparency log

Release files / gittins-1.0.7-cp310-abi3-macosx_11_0_arm64.whl

Download URL gittins-1.0.7-cp310-abi3-macosx_11_0_arm64.whl
Size 285.4 kB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
5da3c7cbb7a6cf2bf4bd289db270fb0b7494c7189b8396ede23cc60e27aafada
BLAKE2b-256 checksum
How to use checksums
4534ee09b88e00d756734543e358d224b3d27a652f1e6e395fde4c25118fbeed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 6, 2026.

Transparency log

Release files / gittins-1.0.7-cp310-abi3-macosx_10_12_x86_64.whl

Download URL gittins-1.0.7-cp310-abi3-macosx_10_12_x86_64.whl
Size 285.4 kB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
35656acaa74d4453707bde958bb12d9b0371eec074031b2be9835cd5a28c7dcc
BLAKE2b-256 checksum
How to use checksums
96fade7164e59aad2f5ce8c5a5b8e9d9ee15c4da5f44f49ab2100fc404cbafd7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 6, 2026.

Transparency log

Security for gittins 1.0.7

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

All 6 files in this release have been uploaded with provenance metadata.

Select from 6 files

Attestation for gittins-1.0.7.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 Oct 6, 2026.

Transparency log

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page