![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
DriftPy is the Python client for the Drift protocol. It allows you to trade and fetch data from Drift using Python.
Read the full SDK documentation here!
pip install driftpy
Note: requires Python >= 3.10.
examples/
folder includes more examples of how to use the SDK including how to provide liquidity/become an lp, stake in the insurance fund, etc.If you are using QuickNode free plan, you must use AccountSubscriptionConfig("demo")
, and you can only subscribe to 1 perp market and 1 spot market at a time.
Non-QuickNode free RPCs (including the public mainnet-beta url) can use cached
as well.
Example setup for AccountSubscriptionConfig("demo")
:
# This example will listen to perp markets 0 & 1 and spot market 0
# If you are listening to any perp markets, you must listen to spot market 0 or the SDK will break
perp_markets = [0, 1]
spot_market_oracle_infos, perp_market_oracle_infos, spot_market_indexes = get_markets_and_oracles(perp_markets = perp_markets)
oracle_infos = spot_market_oracle_infos + perp_market_oracle_infos
drift_client = DriftClient(
connection,
wallet,
"mainnet",
perp_market_indexes = perp_markets,
spot_market_indexes = spot_market_indexes,
oracle_infos = oracle_infos,
account_subscription = AccountSubscriptionConfig("demo"),
)
await drift_client.subscribe()
If you intend to use AccountSubscriptionConfig("demo)
, you must call get_markets_and_oracles
to get the information you need.
get_markets_and_oracles
will return all the necessary OracleInfo
s and market_indexes
in order to use the SDK.
bash setup.sh
Ensure correct python version (using pyenv is recommended):
pyenv install 3.10.11
pyenv global 3.10.11
poetry env use $(pyenv which python)
Install dependencies:
poetry install
To run tests, first ensure you have set up the RPC url, then run pytest
:
export MAINNET_RPC_ENDPOINT="<YOUR_RPC_URL>"
export DEVNET_RPC_ENDPOINT="https://api.devnet.solana.com" # or your own RPC
poetry run pytest -v -s -x tests/ci/*.py
poetry run pytest -v -s tests/math/*.py
FAQs
A Python client for the Drift DEX
We found that driftpy demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.