PrefixSim-python
Python bindings for PrefixSim. The
simulation is PrefixSim's own C++ (the extern/PrefixSim submodule), so results
match its CLI. The Python layer adds:
- cache sizes in bytes (
"24GiB"), from a model's KV size and the trace's block size; - models from their Hugging Face config: KV bytes per token and a prefill-FLOPs cost model;
- parallel sweeps, one process per (algorithm, cache size);
- engine metrics: hits before each request's first miss, which is what vLLM and SGLang reuse.
Install
pip install prefixsim
Wheels are prebuilt for Python 3.10–3.14 on Linux (x86_64 and aarch64, glibc 2.34+: Ubuntu 22.04+, Debian 12+, RHEL 9+) and Apple-silicon macOS, with PrefixSim, libCacheSim, glib and zstd inside: there is nothing to compile or install first. Elsewhere pip builds from source, which needs a C++17 compiler, glib, zstd and Python's headers.
Use
import prefixsim
trace = prefixsim.download_trace("freeinference") # 76 MB, cached by Hugging Face
# blocks, as the CLI
results = prefixsim.simulate(trace, "16k", "lru,s3fifo", cost_model="qwen3coder30b_blksz_16")
# bytes: the model sets the block's size and the cost model
model = prefixsim.ModelSpec.from_hf("Qwen/Qwen3-Coder-30B-A3B-Instruct")
if __name__ == "__main__": # sweep spawns worker processes
results = prefixsim.sweep(trace, ["lru", "s3fifo", "random_compute"],
["24GiB", "48GiB", "96GiB"], model=model, csv_path="results.csv")
Each result is a dict. pandas.DataFrame(results) gives a table.
prefixsim.convert("trace.jsonl", "trace.lcp.zst") turns a JSONL trace into
lcp, which streams instead of being loaded whole.
Metrics
block_hit_ratio and compute_saving_ratio are PrefixSim's. They count every
resident block, past a miss too (doc/design.md, "A block after a miss still
counts"). engine_hit_ratio and engine_compute_saving_ratio stop at the
request's first miss. The bindings measure them by probing each request's blocks
just before PrefixSim serves it, which costs about 4% time
(engine_metrics=False turns it off). The two can rank policies differently.
Here is freeinference at 16k blocks with qwen3coder30b_blksz_16:
| Algorithm | compute_saving_ratio |
engine_compute_saving_ratio |
|---|---|---|
lru |
0.5333 | 0.5333 |
s3fifo |
0.5491 | 0.4984 |
sieve |
0.5459 | 0.5036 |
random_compute |
0.6378 | 0.3375 |
They are equal for lru only under the defaults, replay_order="deepest-first"
and block_id="prefix". In that case a request touches a block's parent after
the block, so the parent is always newer and LRU's victim is a leaf. With
prefix-order replay, or with raw ids where one id can sit under different
parents, LRU leaves gaps too.
Notes
- Models. Only standard attention (MHA/GQA/MQA) and MLA, dense or MoE, are
handled. Configs with sliding-window or linear-attention layers are refused
(
strict=Falsecounts them as full attention). The bundled traces were cut with Qwen3-Coder's tokenizer, so another model changes a block's bytes and cost, not where the blocks are. - Randomized algorithms. Their random number generators are reset before
every run, so a run matches the CLI whatever ran before it;
seed=picks another stream. - Aborts. PrefixSim aborts the process on some errors, for example
s3fifobelow 10 blocks.sweepruns each simulation in its own process and reports which runs were lost. - Sizes.
"64g"is refused, because the CLI reads it as 2³⁰ × 64 blocks. Write"64GiB". - tcmalloc is left out: it cannot be loaded into a running Python process.
- License. Apache-2.0, as PrefixSim and libCacheSim. The Linux wheels link
GLib (LGPL-2.1-or-later) statically; see
third_party/NOTICE.md.
Releasing
.github/workflows/wheels.yml builds and tests every wheel on each push.
Running it by hand publishes to TestPyPI, and publishing a GitHub release
publishes to PyPI, both through trusted publishing. To build locally:
uvx cibuildwheel --platform linux (needs Docker), or uv build --sdist.
Metadata
Release files for prefixsim 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 |
|---|---|---|---|---|
| prefixsim-0.1.0.tar.gz | 6.3 MB | With provenance | Details for prefixsim-0.1.0.tar.gz |
Built distributions (wheels)
Total release size: 21.6 MB
Release files / prefixsim-0.1.0.tar.gz
| Download URL | prefixsim-0.1.0.tar.gz |
|---|---|
| Size | 6.3 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b191bd1719e90842225fc17a20663d92d90e28be8e1f9446a66014fc1451f8f3
|
|
BLAKE2b-256 checksum How to use checksums |
1a9b23ab4e5da88c980af019b96abbb39176b04726fe682498c16b63acdff76d
|
| 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 7, 2026.
Transparency logRelease files / prefixsim-0.1.0-cp314-cp314-manylinux_2_34_x86_64.whl
| Download URL | prefixsim-0.1.0-cp314-cp314-manylinux_2_34_x86_64.whl |
|---|---|
| Size | 926.8 kB |
| Tags | CPython 3.14 Linux glibc 2.34+ x86-64 |
|
SHA-256 checksum How to use checksums |
96de58953fd8ba0895162e536d0d514201ab452a24b99142aed541bba4747f6d
|
|
BLAKE2b-256 checksum How to use checksums |
d077407fb1ba8ac25b2e95d56611f5d3cb151639d6a3e6a91d86f7a0b5e67ae7
|
| 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 7, 2026.
Transparency logRelease files / prefixsim-0.1.0-cp314-cp314-manylinux_2_34_aarch64.whl
| Download URL | prefixsim-0.1.0-cp314-cp314-manylinux_2_34_aarch64.whl |
|---|---|
| Size | 885.7 kB |
| Tags | CPython 3.14 Linux glibc 2.34+ ARM64 |
|
SHA-256 checksum How to use checksums |
9aa935e0c615774813843ef401d8261d4246882df3210610f47a6426b49114be
|
|
BLAKE2b-256 checksum How to use checksums |
288fa9637b5130d588339881bb1b206f3398ecba12b5c671cf0811ea8f54144c
|
| 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 7, 2026.
Transparency logRelease files / prefixsim-0.1.0-cp314-cp314-macosx_15_0_arm64.whl
| Download URL | prefixsim-0.1.0-cp314-cp314-macosx_15_0_arm64.whl |
|---|---|
| Size | 1.3 MB |
| Tags | CPython 3.14 macOS 15.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
04ced63efda3e1cd21c07438f34c8f682282ad48d945f9cfbd199b81be992d6f
|
|
BLAKE2b-256 checksum How to use checksums |
e8a532525c690e18dcf341b37ea7be8bfb4449633f15c8028ebac638f20b6f62
|
| 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 7, 2026.
Transparency logRelease files / prefixsim-0.1.0-cp313-cp313-manylinux_2_34_x86_64.whl
| Download URL | prefixsim-0.1.0-cp313-cp313-manylinux_2_34_x86_64.whl |
|---|---|
| Size | 926.7 kB |
| Tags | CPython 3.13 Linux glibc 2.34+ x86-64 |
|
SHA-256 checksum How to use checksums |
58a402a919b1507776201f9f59fbe6f5161dcf39c689174b0c73bcd60b6c1d5d
|
|
BLAKE2b-256 checksum How to use checksums |
62ae9a20f890f919237b0a5f5311bc92ebf0f2d0c818280c13bfe39cf85d37a9
|
| 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 7, 2026.
Transparency logRelease files / prefixsim-0.1.0-cp313-cp313-manylinux_2_34_aarch64.whl
| Download URL | prefixsim-0.1.0-cp313-cp313-manylinux_2_34_aarch64.whl |
|---|---|
| Size | 885.2 kB |
| Tags | CPython 3.13 Linux glibc 2.34+ ARM64 |
|
SHA-256 checksum How to use checksums |
04301c7dcda10f004b403d4f25c73eb9b7906ad09a72c2ed9cfe511d25f3f2f4
|
|
BLAKE2b-256 checksum How to use checksums |
6ac3a38503bf6f8d98a4780275a595502f2e29cca60ced4c4a9a928c4b05a298
|
| 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 7, 2026.
Transparency logRelease files / prefixsim-0.1.0-cp313-cp313-macosx_15_0_arm64.whl
| Download URL | prefixsim-0.1.0-cp313-cp313-macosx_15_0_arm64.whl |
|---|---|
| Size | 1.3 MB |
| Tags | CPython 3.13 macOS 15.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
2a64ea857af5afa181fd65d5ce7356764da30215f1a6cc8f8b01d17d3d5837bc
|
|
BLAKE2b-256 checksum How to use checksums |
addc3af47e66baa1325c3fac04ca253a3f207b2d038deecce0f6340b58f36964
|
| 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 7, 2026.
Transparency logRelease files / prefixsim-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl
| Download URL | prefixsim-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl |
|---|---|
| Size | 926.8 kB |
| Tags | CPython 3.12 Linux glibc 2.34+ x86-64 |
|
SHA-256 checksum How to use checksums |
efe2da18b2cfb4d077506147fd3fc5a89428c9109d79d531d8f3aea4cc34fc60
|
|
BLAKE2b-256 checksum How to use checksums |
afe6572a68c80ecebd7027037519cdb1cfd5023e33620d482768b8f4f5dc04b5
|
| 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 7, 2026.
Transparency logRelease files / prefixsim-0.1.0-cp312-cp312-manylinux_2_34_aarch64.whl
| Download URL | prefixsim-0.1.0-cp312-cp312-manylinux_2_34_aarch64.whl |
|---|---|
| Size | 885.2 kB |
| Tags | CPython 3.12 Linux glibc 2.34+ ARM64 |
|
SHA-256 checksum How to use checksums |
e6aeb71f8057f50917a1caff9cd4c3b322934f82502739c8870afca45a1d88f1
|
|
BLAKE2b-256 checksum How to use checksums |
38291c796ba7c8a118d24c5258e7e722eef746399301560c71026e010d7b5a0a
|
| 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 7, 2026.
Transparency logRelease files / prefixsim-0.1.0-cp312-cp312-macosx_15_0_arm64.whl
| Download URL | prefixsim-0.1.0-cp312-cp312-macosx_15_0_arm64.whl |
|---|---|
| Size | 1.3 MB |
| Tags | CPython 3.12 macOS 15.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
a827069edba3b64db5af9176d466f99cc71cf28f06df40d4f385e167cb1342db
|
|
BLAKE2b-256 checksum How to use checksums |
fb2d0c1b84506cfe16d620b1559b4f55c1970d51b63c9ac06013bddee71e9705
|
| 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 7, 2026.
Transparency logRelease files / prefixsim-0.1.0-cp311-cp311-manylinux_2_34_x86_64.whl
| Download URL | prefixsim-0.1.0-cp311-cp311-manylinux_2_34_x86_64.whl |
|---|---|
| Size | 926.1 kB |
| Tags | CPython 3.11 Linux glibc 2.34+ x86-64 |
|
SHA-256 checksum How to use checksums |
e8936e1663be6eba755318abc4bdeb4ef1a2aba1f5fc3921051f013e22d1d425
|
|
BLAKE2b-256 checksum How to use checksums |
fd0232db23c9d9fb23381d1d66414e85a5beaf4b33d7fea2a3b0807bb7af6c93
|
| 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 7, 2026.
Transparency logRelease files / prefixsim-0.1.0-cp311-cp311-manylinux_2_34_aarch64.whl
| Download URL | prefixsim-0.1.0-cp311-cp311-manylinux_2_34_aarch64.whl |
|---|---|
| Size | 884.7 kB |
| Tags | CPython 3.11 Linux glibc 2.34+ ARM64 |
|
SHA-256 checksum How to use checksums |
a23e97bdad68b464f348970d88017c52eecb6c07b043cd32bff4a5d9888c5899
|
|
BLAKE2b-256 checksum How to use checksums |
75417dcc05f68656e51852175b88ae1ff774190288ca1071c8b23995a97e98ca
|
| 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 7, 2026.
Transparency logRelease files / prefixsim-0.1.0-cp311-cp311-macosx_15_0_arm64.whl
| Download URL | prefixsim-0.1.0-cp311-cp311-macosx_15_0_arm64.whl |
|---|---|
| Size | 1.3 MB |
| Tags | CPython 3.11 macOS 15.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
98e393e927898c58cec90c6bcc6b2fe93deb059d6ba9d6666db63d06639a26d9
|
|
BLAKE2b-256 checksum How to use checksums |
ff69d743b5e15f5b094cd37544470d93e7978855113a67526c5f7ac9075dd7fa
|
| 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 7, 2026.
Transparency logRelease files / prefixsim-0.1.0-cp310-cp310-manylinux_2_34_x86_64.whl
| Download URL | prefixsim-0.1.0-cp310-cp310-manylinux_2_34_x86_64.whl |
|---|---|
| Size | 925.1 kB |
| Tags | CPython 3.10 Linux glibc 2.34+ x86-64 |
|
SHA-256 checksum How to use checksums |
4687d2df8ad64832b7f6a1267e46054c9620668fab3ba1c118dbda8b9de0a4fa
|
|
BLAKE2b-256 checksum How to use checksums |
3d3a8da8c5dba038354b675df0edbab8794f9752c6ff443f17d8e672a29a52a6
|
| 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 7, 2026.
Transparency logRelease files / prefixsim-0.1.0-cp310-cp310-manylinux_2_34_aarch64.whl
| Download URL | prefixsim-0.1.0-cp310-cp310-manylinux_2_34_aarch64.whl |
|---|---|
| Size | 883.7 kB |
| Tags | CPython 3.10 Linux glibc 2.34+ ARM64 |
|
SHA-256 checksum How to use checksums |
a816c6447d670048e93f96d753cb840a59ad2c6eb2f125809dd3ce990c5a3ad7
|
|
BLAKE2b-256 checksum How to use checksums |
a697e787eca13555faedae2ef56dbe63ebc45a54dbf3fa90b0f37195f48383ac
|
| 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 7, 2026.
Transparency logRelease files / prefixsim-0.1.0-cp310-cp310-macosx_15_0_arm64.whl
| Download URL | prefixsim-0.1.0-cp310-cp310-macosx_15_0_arm64.whl |
|---|---|
| Size | 1.3 MB |
| Tags | CPython 3.10 macOS 15.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
0fe066b3684ffbbf9b139280888a26ba30546f8783d38ed91e0ebcf5c1875b94
|
|
BLAKE2b-256 checksum How to use checksums |
f5d6f3886745fc513868cecaa0384b4fb5b86fbb3597fd368f6093772e30c65f
|
| 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 7, 2026.
Transparency logSecurity for prefixsim 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
All 16 files in this release have been uploaded with provenance metadata.
Attestation for prefixsim-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 7, 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.