Skip to main content

johnnybt-trading

CI PyPI Python License: MIT

Runtime foundation for the johnnybt trading systems.

Four capabilities over one Tokio runtime, so a Python trading process gets concurrency without Python threads and without Python subprocesses: a timer, an embedded RESP server, an HTTP server, and async SQLite with a SQLAlchemy dialect. Everything asynchronous returns an ordinary awaitable, so it composes with asyncio like any other library.

There are no Python dependencies. Every capability is compiled into the extension module — a foundation that dragged a web framework and a database driver in behind it would not be a foundation.

pip install johnnybt-trading
# the SQLAlchemy dialect is optional
pip install "johnnybt-trading[sqlalchemy]"

Requires Python 3.14. That is the only version this is built against and tested on; the extension is compiled abi3, but nothing below 3.14 is claimed or supported.

Prebuilt wheels: Linux (x86_64, aarch64, musl x86_64), macOS (x86_64, arm64), Windows (x64) — one wheel per platform.

Timer

every ticks in Rust. A callback that runs long is a measured skip, not a silent drift, and never an overlapping run — the counters say which happened.

import johnnybt_trading as jbt

handle = jbt.every(0.2, tick, on_error=report, fire_immediately=True)
...
print(handle.fired, handle.skipped, handle.failed)
handle.cancel()

RESP server

RedisServer speaks enough Redis to be a real one to a client that cannot install anything to speak something else — which is the situation when the process on the far side is a broker terminal.

server = jbt.RedisServer(bind="127.0.0.1:6381", password=None, databases=16)
address = await server.start()
...
await server.stop()

Pub/sub is on the same object: server.publish(channel, payload) and server.subscribe(channel). A slow subscriber loses its oldest message rather than stalling the publisher.

HTTP server

Axum routing into Python coroutine handlers, plus a static directory served straight off disk.

server = jbt.HttpServer(bind="127.0.0.1:8080", on_error=report)
server.route("GET", "/healthz", lambda request: jbt.Response(b"ok"))
# Big files never enter Python: Range, conditional GET and compression for free.
server.static_dir("/assets", "dist/assets", cache_seconds=31536000, immutable=True)
address = await server.start()

SQLite

One connection per actor thread, ?-style parameters, and an event log that lives in the same database — which is what lets an event and the fact it describes commit together.

db = await jbt.connect("trades.db")
await db.execute("CREATE TABLE fills (id INTEGER PRIMARY KEY, code TEXT)")
await db.execute("INSERT INTO fills (code) VALUES (?)", ["002105.SZ"])

await db.create_event_schema()
await db.append_event("orders", "filled", b'{"code": "002105.SZ"}')
for event in await db.read_events("orders", after=0):
    ...

The SQLAlchemy async dialect registers itself, so sqlite+jbt:// resolves without an explicit call:

from sqlalchemy.ext.asyncio import create_async_engine

engine = create_async_engine("sqlite+jbt:///trades.db")

Pub/sub or event log?

Both ship, and they answer different questions. Pub/sub tells whoever is listening now — nothing is kept, a subscriber that was not there missed it. The event log tells whoever reads later — appended in order, read from a cursor, and durable in the same transaction as the change it describes.

Development

uv sync --all-extras --dev
uv run maturin develop --uv
uv run pytest
cargo test --lib

License

MIT

Download files

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

Source Distribution

johnnybt_trading-0.1.1.tar.gz (130.4 kB view details)

Uploaded Source

Built Distributions

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

johnnybt_trading-0.1.1-cp311-abi3-win_amd64.whl (2.8 MB view details)

Uploaded CPython 3.11+Windows x86-64

johnnybt_trading-0.1.1-cp311-abi3-musllinux_1_2_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.11+musllinux: musl 1.2+ x86-64

johnnybt_trading-0.1.1-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.9 MB view details)

Uploaded CPython 3.11+manylinux: glibc 2.17+ x86-64

johnnybt_trading-0.1.1-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.8 MB view details)

Uploaded CPython 3.11+manylinux: glibc 2.17+ ARM64

johnnybt_trading-0.1.1-cp311-abi3-macosx_11_0_arm64.whl (2.7 MB view details)

Uploaded CPython 3.11+macOS 11.0+ ARM64

johnnybt_trading-0.1.1-cp311-abi3-macosx_10_12_x86_64.whl (2.8 MB view details)

Uploaded CPython 3.11+macOS 10.12+ x86-64

File details

Details for the file johnnybt_trading-0.1.1.tar.gz.

File metadata

  • Download URL: johnnybt_trading-0.1.1.tar.gz
  • Upload date:
  • Size: 130.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.11 {"installer":{"name":"uv","version":"0.12.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for johnnybt_trading-0.1.1.tar.gz
Algorithm Hash digest
SHA256 abf321a57365f173ec4137853ea888bd82f4cd79f32b6336fd3709d28a54a1a1
MD5 255c90d552e420109783e1f591e76899
BLAKE2b-256 64a83a5d9eefc7813d5a841143422fc0da8019ff9e1b7d6ba70300a317a65b16

See more details on using hashes here.

File details

Details for the file johnnybt_trading-0.1.1-cp311-abi3-win_amd64.whl.

File metadata

  • Download URL: johnnybt_trading-0.1.1-cp311-abi3-win_amd64.whl
  • Upload date:
  • Size: 2.8 MB
  • Tags: CPython 3.11+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.11 {"installer":{"name":"uv","version":"0.12.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for johnnybt_trading-0.1.1-cp311-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 f940fbcd3b86955fb85fa2e9db37355bbb349a36deed6bff0e2fcb05c82faca7
MD5 ed93f2240762c2522b5aa2dcd24dec16
BLAKE2b-256 f97b36879afaef26136ea90b775e143aa4f552ee5a2519120017e6eed9499e60

See more details on using hashes here.

File details

Details for the file johnnybt_trading-0.1.1-cp311-abi3-musllinux_1_2_x86_64.whl.

File metadata

  • Download URL: johnnybt_trading-0.1.1-cp311-abi3-musllinux_1_2_x86_64.whl
  • Upload date:
  • Size: 3.2 MB
  • Tags: CPython 3.11+, musllinux: musl 1.2+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.11 {"installer":{"name":"uv","version":"0.12.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for johnnybt_trading-0.1.1-cp311-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 a11649bec57a14c83ca842845af1080de5bd488c8dbda5bcde43ddd5d92f55c5
MD5 f6c0da914da6f80306c9b5301b55cdb2
BLAKE2b-256 2b527cb1a3d7a00f1b919657d9acb39040497c0fa7097c25fd6a173964049c32

See more details on using hashes here.

File details

Details for the file johnnybt_trading-0.1.1-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

  • Download URL: johnnybt_trading-0.1.1-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 2.9 MB
  • Tags: CPython 3.11+, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.11 {"installer":{"name":"uv","version":"0.12.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for johnnybt_trading-0.1.1-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3711beebeb87e9aaebc8df3137092580f958b66821defaeaca6d65a480fce0e6
MD5 ef553aeec9bb29e6681911b83d583f99
BLAKE2b-256 471d0737250f14ffe666a14c85d979ae2ab4af981e1ec30aca4cc0f0e757ef49

See more details on using hashes here.

File details

Details for the file johnnybt_trading-0.1.1-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

  • Download URL: johnnybt_trading-0.1.1-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
  • Upload date:
  • Size: 2.8 MB
  • Tags: CPython 3.11+, manylinux: glibc 2.17+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.11 {"installer":{"name":"uv","version":"0.12.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for johnnybt_trading-0.1.1-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 1b341094a2f8dde06f6871e60c590db43b3e4c8ef36591c5d8ffc278272831de
MD5 f2ef6e630b90d995a16c756d2aafaf6d
BLAKE2b-256 4f629c84a28549ea8e118830546e94190ae82e112a28cba2996b20d42f20be92

See more details on using hashes here.

File details

Details for the file johnnybt_trading-0.1.1-cp311-abi3-macosx_11_0_arm64.whl.

File metadata

  • Download URL: johnnybt_trading-0.1.1-cp311-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 2.7 MB
  • Tags: CPython 3.11+, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.11 {"installer":{"name":"uv","version":"0.12.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for johnnybt_trading-0.1.1-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3b5d570cd7714b8311024e478a1d7810d0d4f4df8b5fa267bafc97bc4a8feaa4
MD5 81a87eed4ed71d40166ef8eb6c98fcb5
BLAKE2b-256 dca8b411ca8616f34ec12de1542aa052d9e3466512294107d3bc3339b0477a65

See more details on using hashes here.

File details

Details for the file johnnybt_trading-0.1.1-cp311-abi3-macosx_10_12_x86_64.whl.

File metadata

  • Download URL: johnnybt_trading-0.1.1-cp311-abi3-macosx_10_12_x86_64.whl
  • Upload date:
  • Size: 2.8 MB
  • Tags: CPython 3.11+, macOS 10.12+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.11 {"installer":{"name":"uv","version":"0.12.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for johnnybt_trading-0.1.1-cp311-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 af4ec5673206daabc2907278e2fc63d73df31a434ba962c64e21959e2df3f4ab
MD5 102fad8cfce1e305f44eb6faf0e5e0af
BLAKE2b-256 0b6f0a509f2e9ced9f7973403056edbe79cbcc1f1b4e4f75786671c4f75fd0ea

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.1 This release

7 files

0.1.0

7 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