DriftPy is the Python client for the Drift protocol. It allows you to trade and fetch data from Drift using Python.
pip install driftpy
Note: requires Python >= 3.9.
- run
git submodule init
andgit submodule update
to get the protocol-v1 codebase
If you want to contribute to DriftPy, follow these steps to get set up:
- Install poetry
- Install dev dependencies (in local env):
poetry install
- Install nox-poetry (note: do not use Poetry to install this, see here)
- Run
make test
. - Run
make lint
.
- run
anchor build
indrift-core/
withv0.19.0
- modify
drift-core/program
pubkeys to matchtarget/deploy/{...}-keypair.json
pubkeys (can usesolana-keygen pubkey {..}.json
view pubkeys) -- for example, forprograms/clearing_house/src/lib.rs
:
// #[cfg(feature = "mainnet-beta")]
// declare_id!("...");
// #[cfg(not(feature = "mainnet-beta"))]
declare_id!("{...}"); // use `solana-keygen pubkey target/deploy/clearing_house-keypair.json` here
- also change clearing-house address in
drift-core/Anchor.toml
with the same value
[programs.localnet]
clearing_house = "{...}"
- re-build:
anchor build
-
when running tests, you need to kill the validator after each test run
-
you can shutdown the validator by finding its PID with
ps aux | grep solana
and sending a kill command,kill {PID}
-
example with fish shell below:
pytest -v; bash -c $(kill $(ps aux | grep solana | string split ' ' --no-empty | awk "NR==2"))
Run mkdocs serve
to build the docs and serve them locally.
DriftPy ships with IDL files for the user's convenience. These live at src/driftpy/idl
if you need to update them.
- Make sure CHANGELOG.md is updated.
- Run
bumpversion major|minor|patch
to update the version number locally and create a tagged commit. - Run
git push origin <version_number>
to push the tag to GitHub. - After merging your PR on GitHub, create a new release at https://github.com/drift-labs/driftpy/releases. The CI process will upload a new version of the package to PyPI.
- This repo pulls in the main Drift repo using git subtree. Follow that linked tutorial if you want to see how it was done.
The short answer:
git subtree pull --prefix drift-core drift-protocol mainnet-beta --squash