Skip to main content

Wickra Gym — a Gymnasium-compatible, microstructure-aware backtest environment with O(1) steps for fast, deterministic RL rollouts

CI codecov PyPI License: MIT OR Apache-2.0

Wickra Gym — Python


Part of the Wickra ecosystem — for Python. pip install wickra-gym — prebuilt wheels for Linux, macOS and Windows, nothing to compile.

A deterministic, Gymnasium-compatible backtest environment. The whole candle dataset is precomputed once into a fixed feature tensor, so each step() is a constant-time array index — and the same spec, data, seed and actions produce a byte-identical trajectory across every language binding.

Install

pip install wickra-gym

Pre-built wheels ship for Linux, macOS and Windows — there is nothing to compile and no C library to track down.

Quick start

examples/python/rollout.py is the runnable example the CI smoke job executes; in full:

"""Raw rollout over the native command surface (no Gymnasium required).

    python examples/python/rollout.py

Reads the momentum_discrete spec and its candle dataset, then drives a fixed
long policy through the environment via ``RawEnv.command`` — the same JSON-in /
JSON-out boundary every language binding forwards verbatim, so this trajectory
is byte-identical to the C, Node, Go, C#, Java and R examples on the same seed.
"""

import json
from pathlib import Path

from wickra_gym import RawEnv, __version__

DATA = Path(__file__).resolve().parent.parent / "data"

def main() -> None:
    spec = (DATA / "specs" / "momentum_discrete.json").read_text()
    candles = json.loads((DATA / "candles.json").read_text())

    env = RawEnv(spec)
    env.command(json.dumps({"cmd": "load", "candles": candles}))

    reset = json.loads(env.command(json.dumps({"cmd": "reset", "seed": 42})))
    print(f"wickra-gym {__version__}")
    print("reset observation:", reset["observation"])

    equity = 0.0
    step = 0
    while True:
        result = json.loads(env.command(json.dumps({"cmd": "step", "action": 2})))
        equity += result["reward"]
        print(
            f"step {step}: reward {result['reward']:+.6f}  equity {equity:+.6f}  "
            f"terminated={result['terminated']} truncated={result['truncated']}"
        )
        if result["terminated"] or result["truncated"]:
            break
        step += 1

if __name__ == "__main__":
    main()

Use as a Gymnasium environment

import numpy as np
from wickra_gym import WickraGymEnv

spec = """{
  "dataset_ref": "demo", "symbol": "BTCUSDT",
  "observation": {"features": [
    {"kind": "price", "field": "close"},
    {"kind": "indicator", "name": "Rsi", "params": [14]}
  ]},
  "action_space": {"type": "discrete", "n": 3},
  "reward": "pnl",
  "episode": {"max_steps": 256, "warmup": 14}
}"""

candles = [
    {"ts": i, "open": 100 + i, "high": 100 + i, "low": 100 + i, "close": 100 + i}
    for i in range(300)
]

env = WickraGymEnv(spec, candles)
obs, info = env.reset(seed=0)
done = False
while not done:
    action = env.action_space.sample()
    obs, reward, terminated, truncated, info = env.step(action)
    done = terminated or truncated

The observation and action spaces are derived from the spec: unbounded observation columns use ±np.inf; a discrete action space becomes spaces.Discrete(n) and a continuous one becomes a 1-D spaces.Box.

Register it under a Gymnasium id:

from wickra_gym import register
register()  # WickraGym-v0

The raw command surface

RawEnv is the thin, dependency-free wrapper over the native command JSON surface — the same boundary every language binding forwards verbatim:

import json
from wickra_gym import RawEnv

env = RawEnv(spec)
env.command(json.dumps({"cmd": "load", "candles": candles}))
reset = json.loads(env.command(json.dumps({"cmd": "reset", "seed": 0})))
step = json.loads(env.command(json.dumps({"cmd": "step", "action": 2})))

Commands: load, reset, step, spec, version. Domain errors come back as {"ok": false, "error": ...}; a bad spec raises ValueError at construction.

Benchmark

Every binding forwards to the same data-driven Rust core, so what this one adds is the call overhead of PyO3, not a different result. The core's throughput is measured by the repository's benchmark suite and the nightly bench.yml run; the numbers, the machine and how to reproduce them are in the repository BENCHMARKS.md.

Documentation

The full guide, the spec reference and the API documentation live in the main repository and the documentation site:

Wickra Gym ships native bindings for Python, Node.js, WASM and Rust, plus a C ABI hub that any C-capable language (C, C++, C#, Go, Java, R) links against — all forwarding to the same data-driven, unsafe-forbidden Rust core.

Security

Found a security issue? Please don't open a public issue. Report it privately via the repository's Security tab ("Report a vulnerability") or email support@wickra.org with a subject line starting [wickra security]. Full policy: https://github.com/wickra-lib/wickra-gym/blob/main/SECURITY.md.

Disclaimer

wickra-gym is research and engineering tooling, not financial advice. A trained agent's backtested performance says nothing about future returns; markets carry risk and you are responsible for your own decisions. wickra-gym is free software you run yourself: no hosted service, no data collection, no warranty.

License

Licensed under either of Apache-2.0 or MIT at your option.

Metadata

Release files for wickra-gym 0.2.3

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

Source distribution (sdist)

Source distribution for wickra-gym 0.2.3
File Size Uploaded Provenance Actions
wickra_gym-0.2.3.tar.gz 76.1 kB Without provenance Details for wickra_gym-0.2.3.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for wickra-gym 0.2.3
File Actions
wickra_gym-0.2.3-cp39-abi3-win_arm64.whl CPython 3.9 abi3 Windows ARM64 Details for wickra_gym-0.2.3-cp39-abi3-win_arm64.whl
wickra_gym-0.2.3-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details for wickra_gym-0.2.3-cp39-abi3-win_amd64.whl
wickra_gym-0.2.3-cp39-abi3-musllinux_1_2_x86_64.whl CPython 3.9 abi3 Linux musl 1.2+ x86-64 Details for wickra_gym-0.2.3-cp39-abi3-musllinux_1_2_x86_64.whl
wickra_gym-0.2.3-cp39-abi3-musllinux_1_2_aarch64.whl CPython 3.9 abi3 Linux musl 1.2+ ARM64 Details for wickra_gym-0.2.3-cp39-abi3-musllinux_1_2_aarch64.whl
wickra_gym-0.2.3-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.9 abi3 Linux glibc 2.17+ x86-64 Details for wickra_gym-0.2.3-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
wickra_gym-0.2.3-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.9 abi3 Linux glibc 2.17+ ARM64 Details for wickra_gym-0.2.3-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
wickra_gym-0.2.3-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details for wickra_gym-0.2.3-cp39-abi3-macosx_11_0_arm64.whl
wickra_gym-0.2.3-cp39-abi3-macosx_10_12_x86_64.whl CPython 3.9 abi3 macOS 10.12+ x86-64 Details for wickra_gym-0.2.3-cp39-abi3-macosx_10_12_x86_64.whl

Total release size: 5.6 MB

Release files / wickra_gym-0.2.3.tar.gz

Download URL wickra_gym-0.2.3.tar.gz
Size 76.1 kB
Tags Source
SHA-256 checksum
How to use checksums
b7548c9e58dfab28eb820e9e93ee8d9d0a163b21c5db0b58178421f552c03113
BLAKE2b-256 checksum
How to use checksums
3a77ca48443e607badd43edf09b1b92cedcb868488e67056fc63c36ad04aa6cc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / wickra_gym-0.2.3-cp39-abi3-win_arm64.whl

Download URL wickra_gym-0.2.3-cp39-abi3-win_arm64.whl
Size 527.8 kB
Tags CPython 3.9 Windows ARM64 abi3
SHA-256 checksum
How to use checksums
bb3ad781804aab187276f07793eb82578054c87716837c6d5aca01c207257b7a
BLAKE2b-256 checksum
How to use checksums
4dfb4672c778cd1b35b2289d15e9779155fa3dc3a0d6ae61eb9a0d35d275a83f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / wickra_gym-0.2.3-cp39-abi3-win_amd64.whl

Download URL wickra_gym-0.2.3-cp39-abi3-win_amd64.whl
Size 597.4 kB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
ba1f293c22aacd5eac08d5f592138936cbf16962753524bd7c829e4c1cb19fd0
BLAKE2b-256 checksum
How to use checksums
7db92666ee94d18acc53da5179ee2fdb4c76325b008f8d23dd52c918ef36b45e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / wickra_gym-0.2.3-cp39-abi3-musllinux_1_2_x86_64.whl

Download URL wickra_gym-0.2.3-cp39-abi3-musllinux_1_2_x86_64.whl
Size 930.1 kB
Tags CPython 3.9 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
540fe04f20bccb3a125dfbf45bcd0fd814edf62c2906f442c4c34f08440413df
BLAKE2b-256 checksum
How to use checksums
4a2490e2dda30c0956c4c6b4a638cc7b134be5663d95e9b0732a782b33b45a61
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / wickra_gym-0.2.3-cp39-abi3-musllinux_1_2_aarch64.whl

Download URL wickra_gym-0.2.3-cp39-abi3-musllinux_1_2_aarch64.whl
Size 824.6 kB
Tags CPython 3.9 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
60171bee07a034ffaaf69b630a4e3b6ec583bdc08f58c7244a767f88fa49876c
BLAKE2b-256 checksum
How to use checksums
5ecea0c3ace5d840b31e1e743bba3fa110f9fbdc6c0667338494416a4bffd6e3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / wickra_gym-0.2.3-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL wickra_gym-0.2.3-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 714.4 kB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
fb55ce058ce7ab76e626f6297477d7978d93061b7ef84a496efa95fcdc71977f
BLAKE2b-256 checksum
How to use checksums
01cbe240d3e1a390549b04fa7ac22df65cfe216e469dacf82d3620233688bde2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / wickra_gym-0.2.3-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL wickra_gym-0.2.3-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 648.2 kB
Tags CPython 3.9 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
8f277a5259e1485299a742d65c4422fcd50888a8b855f2dc3f533787d74958df
BLAKE2b-256 checksum
How to use checksums
e2096cc9541ed65472203a54e76a3fd156e4a83193d4c0e849f87921867e8807
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / wickra_gym-0.2.3-cp39-abi3-macosx_11_0_arm64.whl

Download URL wickra_gym-0.2.3-cp39-abi3-macosx_11_0_arm64.whl
Size 591.5 kB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
e6cf8c4f1f0d267cac3c6a1b8615531cc6494d844b72e6aeeb61afca8a29ba8c
BLAKE2b-256 checksum
How to use checksums
d0c2067028647cc7d14c3bdb60bdbd3755efee2d82f5f0c585afbe1a56b8fc85
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / wickra_gym-0.2.3-cp39-abi3-macosx_10_12_x86_64.whl

Download URL wickra_gym-0.2.3-cp39-abi3-macosx_10_12_x86_64.whl
Size 683.0 kB
Tags CPython 3.9 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
d631086788cf26d795685f3cb0d100acbbdae8216d16b047eb7ed24718e94205
BLAKE2b-256 checksum
How to use checksums
c975b90f66588fe8c3b528011147a09538c9179fe75dcdbbdfee0303f1a733f5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for wickra-gym 0.2.3

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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

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