Skip to main content

mktlib-scan

Compiled entry/exit chain resolver for mktlib's backtest engine.

pip install mktlib[fast]

That is the whole user-facing story. This package has no API you are meant to call — mktlib discovers it and dispatches to it automatically. Installing it changes performance and nothing else.

What it does

mktlib resolves which entry signals actually open a position by walking the entry/exit chain forward. In pure Python that walk is fast, but getting the data to it is not: Series.to_list() boxes one Python object per element.

Measured in mktlib at 500k bars, before this package existed:

stage time share of a full run()
full run() 129.9 ms —
chain resolution 108.9 ms 85.8%
↳ polars evaluation 0.4 ms 0.3%
↳ to_list() boxing 71.0 ms 54.7%
↳ the scan loop itself 35.7 ms 27.5%

Two-thirds of the cost was marshalling, not computing. So this package takes polars.Series directly and never builds a Python list of floats. An FFI that accepted lists would re-pay that and capture almost nothing — which is the single most important thing to know if you ever change this boundary.

Correctness

mktlib/backtest/_scan.py remains the reference implementation and the fallback. This crate must agree with it bit for bit, and that is enforced rather than asserted:

  • mktlib runs its full equivalence corpus and all of its frozen golden baselines against both backends. The baselines were frozen before this package existed, so any divergence fails.
  • The kernel is a separate crate with no pyo3 and no polars, unit-tested against the rules that are easy to get wrong — entry-wins-on-a-shared-bar, session forcing, NaN-as-null, strictness folding, and the pair/general tie-break.
  • nextafter is pinned bit-for-bit against a table generated from CPython, including the signed zeros, where a sign-propagating implementation diverges.

Bit-identity is achievable here rather than aspirational: the outputs are indices and booleans, and the only float operations are comparisons and nextafter. No accumulation, no reassociation, nothing for an optimizer to reorder.

The semantic contract both implementations satisfy is in CONTRACT.md.

Layout

path what
kernel/ the scan, over slices. No pyo3, no polars, no dependencies.
py/ pyo3-polars shim. Series in, indices out. All marshalling, no semantics.
python/mktlib_scan/ the importable package and its type stubs

License

Apache-2.0

Metadata

Release files for mktlib-scan 0.1.1

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

Source distribution (sdist)

Source distribution for mktlib-scan 0.1.1
File Size Uploaded
mktlib_scan-0.1.1.tar.gz 23.6 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for mktlib-scan 0.1.1
File
mktlib_scan-0.1.1-cp312-abi3-win_amd64.whl CPython 3.12 abi3 Windows x86-64 Details
mktlib_scan-0.1.1-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.12 abi3 Linux glibc 2.17+ x86-64 Details
mktlib_scan-0.1.1-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.12 abi3 Linux glibc 2.17+ ARM64 Details
mktlib_scan-0.1.1-cp312-abi3-macosx_11_0_arm64.whl CPython 3.12 abi3 macOS 11.0+ ARM64 Details
mktlib_scan-0.1.1-cp312-abi3-macosx_10_12_x86_64.whl CPython 3.12 abi3 macOS 10.12+ x86-64 Details

Total release size: 19.1 MB

Release files / mktlib_scan-0.1.1.tar.gz

Download URL mktlib_scan-0.1.1.tar.gz
Size 23.6 kB
Tags Source
SHA-256 checksum
How to use checksums
e983c9787edd3055a993834d8b6d2e40de91b9b01f4377251129ed4ea84da5fa
BLAKE2b-256 checksum
How to use checksums
d333a58f38e85c5f2f2957effe41d1deee25162f3589b5c42b333ac8b43c0a48
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 Aug 7, 2026.

Transparency log

Release files / mktlib_scan-0.1.1-cp312-abi3-win_amd64.whl

Download URL mktlib_scan-0.1.1-cp312-abi3-win_amd64.whl
Size 4.0 MB
Tags CPython 3.12 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
a269c0be1edc805b8203a1e92167b06882ef7ae1eba4258585167932bcd19f94
BLAKE2b-256 checksum
How to use checksums
5c8f290e1f9fc6bffb7e8c54511b35fae085fbaed600f438fb8f6c06afb8a02e
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 Aug 7, 2026.

Transparency log

Release files / mktlib_scan-0.1.1-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL mktlib_scan-0.1.1-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 4.0 MB
Tags CPython 3.12 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
8bbb18cab328f787636acf49e66011140cec87f717ebb41dfa11a92655ecd847
BLAKE2b-256 checksum
How to use checksums
8f15d14d33f8df9e72680dbbfe44ed1bffc729e6c86debccaa9680bf10330675
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 Aug 7, 2026.

Transparency log

Release files / mktlib_scan-0.1.1-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL mktlib_scan-0.1.1-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 3.7 MB
Tags CPython 3.12 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
a42c86b606228d486175a0f58e67c0611287be7b6c13906d31295b501795b044
BLAKE2b-256 checksum
How to use checksums
5a7c9986c1fd2dabdf81b0ce7ffb4c4e5388e3c8a8350ac79bbfb908a9801e6e
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 Aug 7, 2026.

Transparency log

Release files / mktlib_scan-0.1.1-cp312-abi3-macosx_11_0_arm64.whl

Download URL mktlib_scan-0.1.1-cp312-abi3-macosx_11_0_arm64.whl
Size 3.5 MB
Tags CPython 3.12 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
561afaaddc0bd070aafd3319565b27c9e2843aee27d9b8769993ae52c4277460
BLAKE2b-256 checksum
How to use checksums
4ad407a828d88d85d219187ff5e1d9eefca8e079eda145401f2c1cede7f7d102
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 Aug 7, 2026.

Transparency log

Release files / mktlib_scan-0.1.1-cp312-abi3-macosx_10_12_x86_64.whl

Download URL mktlib_scan-0.1.1-cp312-abi3-macosx_10_12_x86_64.whl
Size 3.8 MB
Tags CPython 3.12 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
2ea819eae18aa56ed06cced970e0ade4c57122e825e2bcbc60dff7f1555dfe68
BLAKE2b-256 checksum
How to use checksums
5763b09f2203d47892a07987a803fe7d309a962caa0e86c547105d48c8c84647
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 Aug 7, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.1 This release

6 release files

0.1.0

6 release files

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