# Python SDK
Python-based client for interacting with the Nibiru blockchain.
The nibiru
package allows you to index, query, and send transactions on the Nibiru Blockchain using Python. It provides access to market data for analysis, visualization, indicator development, algorithmic trading, strategy backtesting, bot programming, and related software engineering.
The package is intended to be used by coders, developers, technically-skilled traders and data-scientists for building trading algorithms.
# User Guidelines
# Installation from PyPI
You may need to update pip
to get this to run:
# Documentation Website
Documentation can be found here: Nibiru-py documentation (opens new window)
- Learn more about opening and managing your spot and perp positions here (opens new window)
- Learn about querying the chain using the Sdk here (opens new window)
# Development Guidelines
Our recommended setup is pyenv
in combination with poetry
.
pyenv
is a tool for installing and managing Python interpreters. This will let you seamlessly switch between Python versions.poetry
is used for managing virtual environments, dependency resolution, package installations, package building, and package publishing.- We assume you're on a Unix machine such as WSL2 Ubuntu, MacOS, or a common Linux distro.
Currently, nibiru
is created with Python 3.9.13. It may be compatible with higher versions, but we only run end-to-end tests in 3.9.13.
# Setting up a professional dev environment with pyenv
and poetry
# Pyenv for managing multiple Python interpreters
If you're on MacOS or a common Linux distro, you can install pyenv
with brew.
You'll then need to add the following snippet to your shell config, e.g. your .bash_profile
, .bashrc
, or .zshrc
.
After using source
on your config or restarting the shell, you should have the pyenv
root command.
The command use to install any version of python is pyenv install
. Display additional info for this command with pyenv install --help
.
Once you have a version installed, you can print out the versions on your machine with:
In this example, I have 2 different interpreters installed on my machine. The one with the *
is currently set as my global interpreter. This is set manually using the pyenv global
command.
You can verify this works as expected using python --version
. You may be familiar with using python3
as the command instead of python
. With pyenv
, this is not necessary.
Additional usage and installation instructions can be found in the pyenv repo (opens new window).
# Installing poetry
for dependency resolution and publishing packages
Reference: Poetry docs (opens new window)
Poetry can be installed with both curl
and pip
. We recommended using curl
so that it will be global to your machine.
NOTE We highly, highly, highly recommend that you DO NOT use brew
to install poetry
.
If you use brew
, it's going to install directly to your system, which prevents you from being able to leverage pyenv
to seamlessly switch between Python interpreters.
After this installation command, add the poetry
binary to the path in your shell config (if it's not done automatically).
# Installing external dependencies
The nibiru
project is defined by its pyproject.toml
. At the root of the repo, simply call:
This will resolve dependencies between each of the project's packages and install them into a virtual environment.
# Running tests
# Setting environment variables
There's currently a "devnet" running in GCP that the CI workflows use. You can find these secrets at this notion page (opens new window) if you have access to it or contact one of the CODEOWNERS
(@Unique-Divine, @matthiasmatt, @nibiruheisenberg).
This is useful so that you can run every part of the package code without needing to visit other repositories.
Set up a .env
file to set environment variables for the tests.
The variables used in the CI build can be found in the env
section of the pytests.yml
workflow:
You'll need an .env
configuration like this.
# Running the tests with poetry
+ pytest
After following the instructions for setting up poetry
, you can run the tests with poetry run pytest
:
# (option B). Install the nibiru
package with pip
# Makefile and Protocol Buffers
See the NibiruChain/sdk-proto-gen repository (opens new window).
# Generating types with protobuf
The objective is to run make proto-gen
, which simply executes scripts/protocgen.sh
.
In order to do this, you'll need to install a few packages on your system.
If you get a permissions error such as
call sudo chown -R [USER-NAME] proto
using the name of user directory.
You can find the value for [USER-NAME]
quickly by running whoami
. In other words, this should work:
You're done generating types once you've successfully called
# Linting
Enable git hook which will perform linting before each commit:
This will keep your code clean.
# Gotchas
The protobuf
package must be version 3.20.x or lower. Otherwise, the following error appears at runtime.
# Usage instructions for publishing.
You specify updates to publish using the commit (or PR) title with bump-[version-keyword]
.
For the poetry version
command, ysing any bump rule with a valid semver string will change the version inside pyproject.toml
. For example,
The list of bump rules includes: patch, minor, major, prepatch, preminor, premajor, prerelease.
So the list of available keywords you an put in a PR includes
bump-patch
:bump-patch
: 0.0.0 → 0.0.1bump-minor
: 0.0.* → 0.1.0bump-major
: 0.. → 1.0.0bump-prepatch
: 0.0.0 → 0.0.1-alpha0bump-prerelease
: equivalent tobump-prepatch
bump-preminor
: 0.0.* → 0.1.0-alpha0bump-premajor
: 0.. → 1.0.0-alpha0
These guidelines are in the release.yml for future reference.