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

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.0
File Size Uploaded
mktlib_scan-0.1.0.tar.gz 23.1 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for mktlib-scan 0.1.0
File
mktlib_scan-0.1.0-cp312-abi3-win_amd64.whl CPython 3.12 abi3 Windows x86-64 Details
mktlib_scan-0.1.0-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.0-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.12 abi3 Linux glibc 2.17+ ARM64 Details
mktlib_scan-0.1.0-cp312-abi3-macosx_11_0_arm64.whl CPython 3.12 abi3 macOS 11.0+ ARM64 Details
mktlib_scan-0.1.0-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.0.tar.gz

Download URL mktlib_scan-0.1.0.tar.gz
Size 23.1 kB
Tags Source
SHA-256 checksum
How to use checksums
9a22d9ca0a11118f126ad6fc264a17f3d11eaa96684216af1c953b0964bad923
BLAKE2b-256 checksum
How to use checksums
729e1f6e7ccdef0880fe0363163dd0c0cd598da6293e7a2d1cb1dbbac5041410
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 4, 2026.

Transparency log

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

Download URL mktlib_scan-0.1.0-cp312-abi3-win_amd64.whl
Size 4.0 MB
Tags CPython 3.12 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
a5c11a4f7da833da7dba5b7f5d6e0ce740a711c1ed9ba1de83e9a11305fc3218
BLAKE2b-256 checksum
How to use checksums
0481fed1758b8201c8253ba2e5e56bfc200673d6294ed6776dcec860242c0991
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 4, 2026.

Transparency log

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

Download URL mktlib_scan-0.1.0-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
25902345e156c66b35869efacd3bc079c6991ea9b04e7631b1e252cb47fcd42c
BLAKE2b-256 checksum
How to use checksums
30b0ecdd9d69cc33b5c35dab3b9644938cc0aa1f0210c611e1f1b5220e65cb87
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 4, 2026.

Transparency log

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

Download URL mktlib_scan-0.1.0-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
bb14655a903075d8aa80c801688bb2159fb11d4fbeeef1398bcf454a1fdaa041
BLAKE2b-256 checksum
How to use checksums
27cba4df3cba3930e56f66d60fbd6f5b80517489d8c288680a865b2f3529815f
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 4, 2026.

Transparency log

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

Download URL mktlib_scan-0.1.0-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
4db774b5abd9800a703382a54f19b70a0594143086bdb3ac697a9faa4143728e
BLAKE2b-256 checksum
How to use checksums
392840b2bc7f070649c3db42e486bb196380d80221e716d15e547f1ec0941ea2
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 4, 2026.

Transparency log

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

Download URL mktlib_scan-0.1.0-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
5d682ba7a544640fe32522b00d3690ff8224e711960d8a3f8d29a5b1c15564c8
BLAKE2b-256 checksum
How to use checksums
8fd10947b564294502c9bee34b60281561536145cf4cdaae850fb06c586482b9
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 4, 2026.

Transparency log

Release history Release notifications | RSS feed

0.1.1

6 release files

This release

0.1.0 This release

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