A Python SDK for interacting with the Tranquillo API
Project description
Tranquillo Staking Python SDK
Welcome to the Tranquillo Staking Python SDK - your definitive toolkit for staking and delegation. This SDK provides a streamlined experience for initiating staking flows, handling delegation, and managing signed transactions, ensuring seamless and secure integration the POS networks.
- Tranquillo Staking Python SDK
- Building and Deploying the Tranquillo SDK
Build the Tranquillo SDK Application
Prerequisites for Tranquillo SDK
- Python: Version 3.11 or higher.
- Poetry: Dependency management tool for Python.
Installing Tranquillo SDK Dependencies
Before building the program, ensure you have the following prerequisites:
-
Navigate to the project directory:
cd python_sdk
-
Setup Environment:
Create a virtual environment and activate it:
python3.11 -m venv venv source venv/bin/activate
-
Install the necessary dependencies using Poetry:
poetry install
Running the Tranquillo SDK Application
Starting the Tranquillo API Server
To start the server and import validator keys using mnemonics, use the following command:
poetry run python python_sdk/endpoint_server.py
Running SDK Testing
Tool
poetry run python python_sdk/tester.py
Understanding SDK Output Data
poetry run python python_sdk/tester.py
Flow ID: ['2d514903-2a09-41d6-938d-65965c0d7507']
Delegated State: delegated
Transaction State: broadcasted
SDK Testing Procedures
TTesting Tranquillo SDK Server with curl
Commands
To test the API endpoints, you can use the curl
command-line tool. Here are some example commands:
-
Test the Create Staking Flow Endpoint:
curl -X POST -H "Content-Type: application/json" \ -d '{"flow": {"network_code": "cosmos", "chain_code": "testnet", "operation": "staking"}}' \ http://127.0.0.1:5000/api/v1/flows
-
Test the Delegate Endpoint (Replace
{flow_id}
with the actual flow ID):curl -X PUT -H "Content-Type: application/json" \ -d '{"name": "create_delegate_tx", "inputs": {"delegator_address": "your_address", "validator_address": "validator_address", "amount": 100}}' \ http://127.0.0.1:5000/api/v1/flows/{flow_id}/next
-
Test the Signed Delegate Endpoint (Replace
{flow_id}
with the actual flow ID):curl -X PUT -H "Content-Type: application/json" \ -d '{"name": "sign_delegate_tx", "inputs": {"transaction_payload": "your_payload"}, "signatures": ["signature1", "signature2"]}' \ http://127.0.0.1:5000/api/v1/flows/{flow_id}/next
Replace placeholders like your_address
, validator_address
, your_payload
, etc., with actual values when executing the commands.
Executing Automated Tests for the SDK
To execute your tests, you can use the following command:
poetry run pytest
# or
poetry run pytest tests/test_tranquillo_client.py
Or, if you are using unittest and your test files are named in the pattern test_*.py, you can use:
poetry run python -m unittest discover
Running a Single Test File
To run a specific test file, simply provide the path to the file. For example:
poetry run pytest tests/test_my_feature.py
Performing Coverage Analysis for SDK Tests
Run tests with coverage using the following command:
poetry run pytest --cov=python_sdk/.
Generating Test Coverage Reports for the SDK
Terminal Report:
poetry run pytest --cov=python_sdk/. --cov-report=term
Create HTML Report:
poetry run pytest --cov=python_sdk/. --cov-report=xml
XML Report:
poetry run pytest --cov=your_package_name --cov-report=xml
MongoDB Command Reference for Staking Data Management
This section outlines the MongoDB commands used for querying the staking
database, specifically within the flows
collection.
Accessing and Querying the Staking Database
First, Start mongo cli:
./mongosh
Switch to the staking
database:
use staking
Retrieve and Display All Documents in flows Collection
This command fetches all documents from the flows collection and displays them in a formatted manner.
db.flows.find().pretty()
Find a Specific Document by Flow ID
Replace your_flow_id with the actual ID of the flow you want to query.
db.flows.find({"flow_id": "your_flow_id"}).pretty()
Example using a specific flow ID:
db.flows.find({"flow_id": "b2c4c9c9-a6ef-46f7-b1a4-e3aebd9ba84b"}).pretty()
Drop the Collection
Example to drop the flows collection:
db.flows.drop()
Building and Deploying the Tranquillo SDK
Configuring pyproject.toml
for Tranquillo SDK
Ensure your pyproject.toml file is correctly set up with all necessary information. This includes the package name, version, description, dependencies, and any other relevant metadata. Here's an example template:
[tool.poetry]
name = "tranquillo-sdk"
version = "0.1.0"
description = "A Python SDK for interacting with the Tranquillo API"
authors = ["Your Name <youremail@example.com>"]
[tool.poetry.dependencies]
python = "^3.11"
[tool.poetry.dev-dependencies]
pytest = "^7.4.3"
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
Building the Tranquillo SDK Package
To build the package, execute the following command:
poetry build
This command will generate a .tar.gz archive and a .whl file in the dist directory.
Publishing the Tranquillo SDK to PyPI
To publish your package to PyPI (Python Package Index), create a account on PyPI.
Once the account is created, publish your package using:
poetry publish
This command will prompt you for your PyPI username and password. If you are using a CI/CD pipeline, you can also automate this step using API tokens.
Version Control Tagging for SDK Releases
After deploying your package, tag the commit and push the tag to your remote repository:
git tag -a v0.1.0 -m "Release 0.1.0"
git push origin v0.1.0
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for tranquillo_staking_api-0.1.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac5bac063b2a0bd9f5d30b4403350c0483566440172e1a33f54f0c68e4560479 |
|
MD5 | cb3e091d179660ee9d6e1cc057c55cec |
|
BLAKE2b-256 | 69ee16422d5698645c3e1b8888615f9e9bf4c92e12bf0d4ab236289f64bdcf85 |
Hashes for tranquillo_staking_api-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f94b1466758974c4c2946480ea9b192f757427cb5fa85aa00903fd005f41a2ac |
|
MD5 | a4fb3d0bee7d03bfb3299c67f1aecb49 |
|
BLAKE2b-256 | f58cdf0b9be263e3f3cced9d5f54fa78f9716f4d44d7e1aa06cc4f2fc41d390c |