This guide covers local setup, verification, and working conventions for the Python scaffold.
All Python sources, tests, and requirements live under python/. Create a
virtual environment from the repo root and install runtime dependencies from
python/requirements.txt.
python3 -m venv .venv
source .venv/bin/activate
python3 -m pip install --upgrade pip
python3 -m pip install -r python/requirements.txtInstall development tooling when running tests, lint, or type checks:
python3 -m pip install -r python/requirements-dev.txtpython/requirements-dev.txt includes python/requirements.txt, so it is
enough for a full local development environment.
The tests use pythonpath = ["src"] from python/pyproject.toml, so an
editable install is not required for pytest (run from python/). Install
the package editable when you want the eventcontracts console script
available:
python3 -m pip install -e ./pythonStart from the example file:
cp .env.example .envThe example includes placeholders for Kalshi, Polymarket global, and external
data providers. Do not commit real credentials. CLI commands auto-load the
nearest .env, so you do not need to source .env before running local
commands.
For the current sports-golf research path:
make PYTHON=.venv/bin/python sports-golf-preflight
make PYTHON=.venv/bin/python sports-golf-smokesports-golf-preflight checks that the relevant keys and configs are present
without printing secret values. sports-golf-smoke generates deterministic
bar-compatible golf data, writes a Parquet event lake, and runs the player-cut
and cut-line strategies end to end. DataGolf, PGA Tour, and ShotLink keys are
treated as optional provider upgrades; the local smoke path does not require
them.
For the weather historical paper path:
make PYTHON=.venv/bin/python weather-preflight
PYTHONPATH=python/src .venv/bin/python -m eventcontracts.cli weather-historical \
--ticker KXHIGHNY-26MAY24-B75 \
--threshold-f 75 \
--lat 40.7128 \
--lon -74.0060 \
--location-name NYC \
--start 2026-05-24T12:00:00Z \
--end 2026-05-24T21:00:00Z \
--target-day 2026-05-24weather-historical is the real paper-test path: it fetches Kalshi historical
candlesticks and historical weather forecast data, writes normalized quote and
external-signal events, then runs the existing paper backtester. It places no
live orders.
From the repo root, make quality runs everything in python/. To invoke
the steps directly:
cd python
python3 -m compileall -q src tests
PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 python3 -m pytest
python3 -m ruff check src tests
python3 -m mypy src/eventcontracts testsThe current test suite is intentionally small and focuses on import stability, event/decision type coverage, and the strategy/runner smoke path.
After editable install:
eventcontracts check-config configs/venues/kalshi.tomlWithout editable install (run from the repo root):
PYTHONPATH=python/src python3 -m eventcontracts.cli check-config configs/venues/kalshi.toml- Add a module under
python/src/eventcontracts/plugins/strategies/. - Implement
StrategyBase.on_event. - Register a factory with
@register("strategy_name"). - Import the module in
python/src/eventcontracts/plugins/strategies/__init__.pyso the registry is populated (or expose it via theeventcontracts.strategiesentry-point group inpython/pyproject.toml). - Add a test using the in-memory ports from
eventcontracts.testing.
Domain types should be immutable dataclasses where possible. Prefer adding a new event or decision variant only when the behavior is genuinely cross-cutting. Use metadata fields for venue-specific extra fields until the framework has a clear venue-neutral meaning for them.
When changing the strategy boundary, update:
README.mddocs/architecture.mddocs/strategy-runner-contract.md- tests that show the expected wiring
When changing artifact or model export assumptions, update:
docs/artifact-contract.mddocs/implementation-roadmap.md