Skip to main content

PyCyBase

docs pypi-linux pypi-windows

Common C / Cython dual interfaces for Python HFT Projects.

Overview

Low-level allocator infrastructure shared across HFT projects:

  • Allocator Protocol — Pluggable memory allocation with heap, shared-memory (SHM), and raw malloc backends. Ref-counting, vigilant mode, thread-safety controls.
  • Heap Allocator — In-process allocator with free-list reuse and auto-growing pages.
  • SHM Allocator — POSIX shared-memory page allocator with fixed-address virtual region mapping for cross-process pointer stability.
  • ByteMap — Fast xxHash3-backed hash maps for byte-string keys (ByteMap, ByteMapEx, bound variants).
  • Intern String — FNV-1a-hashed string interning with SHM-backed cross-process pools. 1.7–2.2× speedup over Python str.

Quick Start

from cbase.allocator_protocol import AllocatorProtocol, AP_SHARED

with AP_SHARED:
    alloc = AllocatorProtocol(1024)
    alloc.buf[0] = b'x'
from cbase.intern_string import POOL

aapl = POOL.istr("AAPL")
assert aapl is POOL.istr("AAPL")  # Identity — string deduplication
from cbase.bytemap import ByteMap

bm = ByteMap()
bm[b"ticker"] = b"AAPL"
assert bm[b"ticker"] == b"AAPL"

Build & Install

PyCyBase is a Cython extension package — it cannot be used with pip install -e . (editable mode breaks Cython .pxd resolution for downstream projects).

POSIX (Linux / macOS)

# Build extensions in-place, then install
./build.sh -i

# Or equivalently:
make build && pip install -U . --no-build-isolation

# Or step by step:
python setup.py build_ext --inplace --verbose --force
pip install -U . --no-build-isolation

Build script reference:

Command Effect
./build.sh Clean + build in-place
./build.sh -i Clean + build + pip install .
./build.sh -r Clean + build + force-reinstall
./build.sh -c Clean only (no build)
./build.sh -a Deep clean (remove .c and .so files)
./build.sh -l List all compile-time macros
./build.sh -v /path/to/venv Use a specific venv
make or make build Clean + build
make install Build + pip install .
make reinstall Build + force-reinstall
make list-args List compile-time macros

Windows (NT)

# Local build
.\build.ps1 -VenvPath "C:\Users\...\venv_313"

# Remote build (from Linux host):
python nt_build.py

Compile-Time Macros

Override any macro at build time via environment variable:

DEBUG=1 ./build.sh         # Enable debug mode
DEBUG=1 make build          # Same via Makefile

List all available macros and defaults:

./build.sh -l               # Auto-generates macros.json via probe.py
make list-args
python probe.py             # Run the probe directly

Key macros (see macros.json for full list):

Macro Default Description
AP_ALLOC_VIGILANT 1 Enable bounds/canary checks
AP_ALLOC_WITH_LOCK 1 Thread-safety via pthread mutex
AP_ALLOC_WITH_SHM 0 Default to SHM allocator
AP_ALLOC_WITH_FREELIST 1 Free-list reuse
AP_HEAP_AUTOPAGE_CAPACITY 64 KiB Default heap page size
AP_HEAP_AUTOPAGE_CAPACITY_MAX 16 MiB Max heap page size
AP_HEAP_EXACT_BIN_COUNT 8192 Exact 8-byte-granular free-list bins
AP_HEAP_LARGE_BIN_COUNT 9 Pow2-class free-list bins for large blocks
AP_HEAP_PAGE_EXTEND_MAX 128 MiB Max auto-page extension on bin miss
AP_HEAP_EXACT_BIN_PROBE_COUNT 2 Larger exact bins to probe before extending
AP_SHM_AUTOPAGE_CAPACITY 64 KiB Default SHM page size
AP_SHM_ALLOCATOR_DEFAULT_REGION_SIZE 128 GiB SHM virtual region
AP_SHM_EXACT_BIN_COUNT 8192 Exact 8-byte-granular free-list bins
AP_SHM_PAGE_EXTEND_MAX 128 MiB Max auto-page extension on bin miss

Using get_include() in Downstream Projects

from setuptools import setup, Extension
from Cython.Build import cythonize
import cbase

ext = Extension(
    "my_module",
    sources=["my_module.pyx"],
    include_dirs=cbase.get_include(),
)
setup(ext_modules=cythonize([ext]))

Modules

Module Description
cbase.env EnvConfigContext — context manager for temporary config changes
cbase.allocator_protocol AllocatorProtocol, AllocatorConfigContext, AP sentinels
cbase.allocator_protocol.c_heap_allocator In-process heap allocator with free-list
cbase.allocator_protocol.c_shm_allocator POSIX shared-memory page allocator
cbase.bytemap.c_bytemap xxHash3-backed hash maps
cbase.intern_string.c_intern_string FNV-1a-hashed string interning
cbase.backports.pylong Python int ↔ 128-bit integer (uint128_t/int128_t) backport
cbase.backports.pydict PyDict_Pop backport for pre-3.13 Python

Documentation

pip install sphinx furo
cd docs
sphinx-build -M html . _build
# Or with the project venv:
~/Projects/venv_313/bin/sphinx-build -M html . _build

Open docs/_build/html/index.html.

Online: https://bolunhan.github.io/PyCyBase/

License

Proprietary.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pycybase-0.1.11.post1-cp315-cp315t-win_amd64.whl (3.4 MB view details)

Uploaded CPython 3.15tWindows x86-64

pycybase-0.1.11.post1-cp315-cp315t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (7.1 MB view details)

Uploaded CPython 3.15tmanylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

pycybase-0.1.11.post1-cp315-cp315-win_amd64.whl (3.3 MB view details)

Uploaded CPython 3.15Windows x86-64

pycybase-0.1.11.post1-cp315-cp315-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (7.1 MB view details)

Uploaded CPython 3.15manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

pycybase-0.1.11.post1-cp314-cp314t-win_amd64.whl (3.4 MB view details)

Uploaded CPython 3.14tWindows x86-64

pycybase-0.1.11.post1-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (7.1 MB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

pycybase-0.1.11.post1-cp314-cp314-win_amd64.whl (3.3 MB view details)

Uploaded CPython 3.14Windows x86-64

pycybase-0.1.11.post1-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (7.0 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

pycybase-0.1.11.post1-cp313-cp313-win_amd64.whl (3.3 MB view details)

Uploaded CPython 3.13Windows x86-64

pycybase-0.1.11.post1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (7.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

pycybase-0.1.11.post1-cp312-cp312-win_amd64.whl (3.3 MB view details)

Uploaded CPython 3.12Windows x86-64

pycybase-0.1.11.post1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (7.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

File details

Details for the file pycybase-0.1.11.post1-cp315-cp315t-win_amd64.whl.

File metadata

File hashes

Hashes for pycybase-0.1.11.post1-cp315-cp315t-win_amd64.whl
Algorithm Hash digest
SHA256 afd403ef474fb6116446ba5427d8b1d395b00d0efca4cefd8b9e94f401295b9f
MD5 8d92f725028e5dbfd635836fae6670d8
BLAKE2b-256 aa92928fbe3d79da6530a9919bb73f3eec9fb019044ccd13be58d7487270e5ff

See more details on using hashes here.

File details

Details for the file pycybase-0.1.11.post1-cp315-cp315t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pycybase-0.1.11.post1-cp315-cp315t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f7688eaf568af12d72b0153b2818b96e87d752844aff8d2495a4a5601f9c26b8
MD5 df2914bf10b411485780828a1a86b313
BLAKE2b-256 a565071e64cfed88015f85e46b3e62a7e08ebe30243e65bdb6ad8191a5923580

See more details on using hashes here.

File details

Details for the file pycybase-0.1.11.post1-cp315-cp315-win_amd64.whl.

File metadata

File hashes

Hashes for pycybase-0.1.11.post1-cp315-cp315-win_amd64.whl
Algorithm Hash digest
SHA256 63bc02d00e748214415ff3f6ebeb880d476ee68d2a73787d0ed90f489698433e
MD5 2614d9410eb683aa729f62f5279afa03
BLAKE2b-256 ef0d53ff4be294c03f72d4c02ab31114fbd0769e37ab423ef27f59c65e8584c0

See more details on using hashes here.

File details

Details for the file pycybase-0.1.11.post1-cp315-cp315-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pycybase-0.1.11.post1-cp315-cp315-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 544e4dad9a868fcd6bb8d8469cca17bd3778ae85589fe17385d008459eb977c9
MD5 107bc6f0d6029abbb3961d2555748bc3
BLAKE2b-256 437194ca5525119cf4d1ba6dee8fa79455e7adb6ebbc7bb202a5ac6e7562a8f9

See more details on using hashes here.

File details

Details for the file pycybase-0.1.11.post1-cp314-cp314t-win_amd64.whl.

File metadata

File hashes

Hashes for pycybase-0.1.11.post1-cp314-cp314t-win_amd64.whl
Algorithm Hash digest
SHA256 94d2b279f27a962b99b3e8310b9c028dd641f364a19f5252042996f0635f99cf
MD5 ff29c239fe4178b4cf0e79e777357729
BLAKE2b-256 d1e9cd54cad18528f195caabc515d2c69706cbb5fa9700c489c18530accfca0b

See more details on using hashes here.

File details

Details for the file pycybase-0.1.11.post1-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pycybase-0.1.11.post1-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b1935da79c1665457b83f9a2427516eaafb2afad070577f616c78f425fce21ed
MD5 ebb880da60e075c869df97da07bf7e44
BLAKE2b-256 3850bf22c53ddc0f451f8d3a17cb6e60498e8287a1fe8724a4ab35ddcd063747

See more details on using hashes here.

File details

Details for the file pycybase-0.1.11.post1-cp314-cp314-win_amd64.whl.

File metadata

File hashes

Hashes for pycybase-0.1.11.post1-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 4e255ebc7ceae6ab24f1eaa00be63aa22f2c96be17a89002b8c09b7a72d9f12f
MD5 f144bb52eb3b45fc2fca69650f07a060
BLAKE2b-256 1895eeafaa07b40c5655a00f883f4ea05116ee79046d16bce2571094056012d9

See more details on using hashes here.

File details

Details for the file pycybase-0.1.11.post1-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pycybase-0.1.11.post1-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 75207caf8418798d1cc049903507befb1069d37d7a66e0acfbd413bf76459bb9
MD5 724a9c73e01bc9b1598dc68d99146c37
BLAKE2b-256 80388f2c8040bfe7c1018beb862316588ebec547de71832d5b0ef918b44f7501

See more details on using hashes here.

File details

Details for the file pycybase-0.1.11.post1-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for pycybase-0.1.11.post1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 136ee55083cd99262d52bff183ab52815655aa328204f8db429e90cfc7dc28a5
MD5 204e0ab03bb3a5bb37bfd216e7e92af4
BLAKE2b-256 83077eba237775b6d80f95a6a6345bcb6805e6eac30616d9f98164386dc1ffbc

See more details on using hashes here.

File details

Details for the file pycybase-0.1.11.post1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pycybase-0.1.11.post1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 cb7e8d70a1aad1a2803a6daf957565b6b0e39c22277aa0679a56a114f388c738
MD5 c40d172a7109daffc08d79b07a4ad2af
BLAKE2b-256 803bf81ed23aa49bb58b3513e61a535e97cdeab814e4146c896c9e626115e0f4

See more details on using hashes here.

File details

Details for the file pycybase-0.1.11.post1-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for pycybase-0.1.11.post1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 f86c31368310877ae52cba9d574c015ca7e97b0b0da073b38088e592bbe1ce2e
MD5 6411d50fa69c21d9ee8464a404accb74
BLAKE2b-256 66958f7754014dc4da2f9ec1327107583d2dc9a1ca397b551591ceaf8d38ba80

See more details on using hashes here.

File details

Details for the file pycybase-0.1.11.post1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pycybase-0.1.11.post1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 aec6c6a2c0609144bf3993f80d7e06503ce43f08200ec8c0375f1290eccd47b9
MD5 36c2d2ba7320616505e16a6d6b0a4b9e
BLAKE2b-256 8406868849d376932b61de7a1570c489b99390fb290416fae57c5e2a6cb473c2

See more details on using hashes here.

Release history Release notifications | RSS feed

0.2.9

12 files

0.2.8

12 files

0.2.7

12 files

0.2.6

12 files

0.2.5

12 files

0.2.2

12 files

0.2.1

12 files

0.2.0

12 files

This release

0.1.11.post1 This release

12 files

0.1.11

12 files

0.1.10

12 files

0.1.9

8 files

0.1.8.post5

8 files

0.1.8.post3

4 files

0.1.8.post2

4 files

0.1.8.post1

4 files

0.1.8

4 files

0.1.7.post4

4 files

0.1.7.post2

3 files

0.1.4.post2

4 files

0.1.4.post1

4 files

0.1.3.post1

4 files

0.1.0

4 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