Python 3.9+ library for interacting with a CSPR node.
The python client is published as pycspr
: PYthon CaSPeR. It's goal is to streamline client side experience of interacting with a casper node.
It's recommend to create a virtual environment for your application:
$ cd path/to/your/project
$ virtualenv .venv # if you just starting and need a venv anyway
$ source ./.venv/bin/activate # launch your environment
$ pip install pycspr
If you want to take part in develeopment, follow the intallation instructions for development.
- Query a node See here.
- Transfer funds between 2 accounts See here.
- Delegate funds to a validator See here.
- Undelegate funds from a validator See here.
- Stake funds as a validator See here.
- Unstake funds as a validator See here.
- Install a smart contract See here.
- Invoke a smart contract See here.
______________ Your APP needs to call the NodeClient to
| Your App | make API calls. In addition you may need
|____________| some tools which can be found in factory,
X crypto and utils.
|
=========================== | ================================================
V
_____________ _______________ ______________ More complex
| | | | | | operations and
| Deploys |<------X| NodeClient |X---->|EventsClient| simplification of
| | ----X| | | | composed API/Client
------------- | --------------- -------------- calls.
X |
===== | ======= | ============================================================
V V
_______________________________________ Supposes all API calls and additional
| | | methods, composed of basic API calls.
| Client | pycspr.types | Converts API response into pycspr.types.
|(client.QueryClient)| | Extracts result from API response.
--------------------------------------- Checking and converting input params.
X
=========== | ==================================================================
V
___________________________ "Low Level" communication, REST and RPC Api calls.
| | Does all REST and RPC calls. All endpoints defined
| CasperApi | here. No converting or manipulation of output or
| (pycspr.api) | input params at all. All in all its a simple
--------------------------- interface to the REST/RPC API.
X
=========== | ==================================================================
V
___________________________ ___________________________
| | | |
| NodeConnectionInfo |X-------> | requests, |
| (pycspr.api) | | jsonrpcclient, ... |
--------------------------- ---------------------------
Follow the Casper Documentation: Getting Started
See the Casper Documentation for installation: Local Network Testing
$ nctl-assets-setup && nctl-start
You can stop the server and delete created assets with nctl-assets-teardown
.
after cloning:
$ cd casper-python-sdk/
$ virtualenv .venv
$ source ./.venv/bin/activate
(.venv) $ pip install -r requirements-dev.txt
Always asure that the tests are running and that you follow the PEP.
- NTCL default not set (ie: ~/casper-node/utils/nctl).
- PYCSPR_TEST_NODE_HOST" default set to "localhost")
- PYCSPR_TEST_NODE_PORT_REST default set to 14101)
- PYCSPR_TEST_NODE_PORT_RPC default set to 11101)
- PYCSPR_TEST_NODE_PORT_SSE default set to 18101)
$ cd casper-python-sdk/
$ source .venv/bin/activate # or pipenv shell
(.venv) $ export NCTL=/path/to/your/casper-node/utils/nctl
(.venv) $ pytest ./tests
TODO: Git pre-commit-hook needed.
run flake8 (Style Guide Enforcement):
(.venv) $ cd casper-python-sdk/
(.venv) $ flake8 .
TODO: Git pre-commit-hook needed.
- Json RPC Schema in resources/rpc_schema.json
- Casper Specifcation: https://caspernetwork.readthedocs.io/en/latest/implementation/
- Casper Documentation: https://docs.casperlabs.io/
- How to stake your CSPR: https://casper.network/network/blog/how-to-stake-your-cspr
- Python Enhancement Proposals(PEP): https://www.python.org/dev/peps/