Convex api
Project description
Convex Python SDK
The official Python client library for interacting with the Convex decentralised lattice network.
📚 Documentation
Official documentation is available at docs.convex.world/docs/tutorial/client-sdks/python
- Quickstart Guide - Build your first Python app
- Query Guide - Read network state
- Transaction Guide - Submit transactions
- Account Management - Manage keys and accounts
Installation
pip install convex-sdk
Quick Example
from convex_sdk import Convex, KeyPair
# Connect to the network
convex = Convex('https://peer.convex.live')
# Create a new account
key_pair = KeyPair()
account = convex.create_account(key_pair)
# Request test funds
convex.request_funds(100_000_000, account)
# Query balance
balance = convex.get_balance(account)
print(f'Balance: {balance / 1_000_000_000} Convex Coins')
Resources
- Official Documentation - Complete SDK guide
- PyPI Package - Python Package Index
- Convex Network - Main website
- Discord Community - Get help and share ideas
Development Setup
To set up the project for development, follow these steps:
Prerequisites:
- Python 3.10 or higher
- pip (Python package installer)
Setup Steps:
-
Create a virtual environment:
python -m venv .venv
This creates a virtual environment in a
.venvdirectory. -
Activate the virtual environment:
-
On Windows (PowerShell or Command Prompt):
.venv\Scripts\activate
-
On Windows (Git Bash):
source .venv/Scripts/activate
-
On Linux/Mac:
source .venv/bin/activate
When activated, you should see
(venv)at the beginning of your command prompt. -
-
Upgrade pip (recommended):
python -m pip install --upgrade pip
-
Install the package in development mode with all dependencies:
Option 1 - Using setup.py extras (recommended):
pip install -e ".[dev,test,docs]"
Option 2 - Using requirements files:
pip install -r requirements-dev.txt pip install -e .
-
Verify the installation:
pytest tests
Deactivating the virtual environment: When you're done working, you can deactivate the virtual environment by running:
deactivate
Note: Always activate your virtual environment before working on the project. The virtual environment ensures that dependencies are isolated from your system Python installation.
Quick Start
First you need to download the convex-sdk package from the python package index PyPi.
pip install convex-sdk
You can now access the convex network, and get a balance from an existing account on the network by doing the following:
>>> from convex_sdk import Convex, KeyPair
>>> convex = Convex('https://peer.convex.live')
>>> convex.get_balance(9)
99396961137042
You can create a new empty account, with no balance:
>>> key_pair = KeyPair()
>>> account = convex.create_account(key_pair)
>>> account.address
809
You can request some funds to the new account and then get the account information:
>>> convex.request_funds(1000000, account)
1000000
>>> convex.get_account_info(account)
AccountDetailsResponse(sequence=0, address=809, memorySize=42, balance=1000000, allowance=0, type='user')
You can export the accounts private key encoded as PKCS8 encrypt the key with a password:
>>> account.key_pair.export_to_text('secret')
'-----BEGIN ENCRYPTED PRIVATE KEY-----\nMIGbMFcGCSqGSIb3DQEFDTBKMCkGCSqGSIb3DQEFDDAcBAiMY42UY4PXHAICCAAw\nDAYIKoZIhvcNAgkFADAdBglghkgBZQMEASoEEJpwDMicGbGj2iSJesktIVYEQBsp\nKMTAHzvUyw8jZRr8WSrmxH7938sjma8XWI6lgd9jwTZzcGamog7p3zatw0Wp+jFK\nKruWAZmIqhBZ/2ezDv8=\n-----END ENCRYPTED PRIVATE KEY-----\n'
>>> account.address
809
To re-use your account again you need to import the encrypted private key and set the correct account address
>>> from convex_sdk import Account, KeyPair
>>> key_pair = KeyPair.import_from_file('my_key.dat', 'secret')
>>> account = Account(key_pair, 809)
To create a new address with the same account keys in your new or imported account object, you can do:
>>> new_account = convex.create_account(key_pair)
>>> account.address
809
>>> new_account.address
934
To use account names, where an account name is resolved to a fixed address. You can create or load an account based on it's name by doing the following:
>>> account = convex.setup_account('my-account-name', key_pair)
>>> account.address
934
>>> convex.resolve_account_name('my-account-name')
934
>>> same_account = convex.setup_account('my-account-name', key_pair)
>>> same_account.address
934
To submit a transaction, use Convex.transact(). This will cost a small amount of juice, and reduce your balance
>>> convex.request_funds(1000000, account)
1000000
>>> convex.transact('(map inc [1 2 3 4])', account)
{'value': [2, 3, 4, 5]}
>>> convex.get_balance(account)
996360
To send a query a transaction, this is free and can be performed by any valid account address. So for example to query a balance of an account:
>>> convex.query(f'(balance {account.address})', account)
{'value': 996360}
# this is the same as above
>>> convex.query(f'(balance {account.address})', account.address)
{'value': 996360}
# get the balance using one of the standard account addresses (#1)
>>> convex.query(f'(balance {account.address})', 1)
{'value': 996360}
Project details
Release history Release notifications | RSS feed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file convex_sdk-0.3.3.tar.gz.
File metadata
- Download URL: convex_sdk-0.3.3.tar.gz
- Upload date:
- Size: 33.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f47c7a535d1487170d69c6171ef5158c4c469e8afe6b0ae952d81801108a7577
|
|
| MD5 |
6c882d95204c0f50187b3f933e64488e
|
|
| BLAKE2b-256 |
2f2930afc826525ee9d78782a521d12ad2bcf8cee81ec75ae7080ffe2c51e84a
|
Provenance
The following attestation bundles were made for convex_sdk-0.3.3.tar.gz:
Publisher:
publish.yml on Convex-Dev/convex-api-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
convex_sdk-0.3.3.tar.gz -
Subject digest:
f47c7a535d1487170d69c6171ef5158c4c469e8afe6b0ae952d81801108a7577 - Sigstore transparency entry: 1868990708
- Sigstore integration time:
-
Permalink:
Convex-Dev/convex-api-py@1811f5cd2d4253268f3136f97f782c0ae14b09b3 -
Branch / Tag:
refs/tags/v0.3.3 - Owner: https://github.com/Convex-Dev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@1811f5cd2d4253268f3136f97f782c0ae14b09b3 -
Trigger Event:
push
-
Statement type:
File details
Details for the file convex_sdk-0.3.3-py2.py3-none-any.whl.
File metadata
- Download URL: convex_sdk-0.3.3-py2.py3-none-any.whl
- Upload date:
- Size: 39.6 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
370d8088f8ba2394ce36d7ccaea4309b6253348f866a16c7e06b19eca0921041
|
|
| MD5 |
b31aa8674f905abb7827f1175b72cecd
|
|
| BLAKE2b-256 |
5033a67b167a9141a6e3a3b7454b739a17635fcd1b07dc9031cb83b76df578ac
|
Provenance
The following attestation bundles were made for convex_sdk-0.3.3-py2.py3-none-any.whl:
Publisher:
publish.yml on Convex-Dev/convex-api-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
convex_sdk-0.3.3-py2.py3-none-any.whl -
Subject digest:
370d8088f8ba2394ce36d7ccaea4309b6253348f866a16c7e06b19eca0921041 - Sigstore transparency entry: 1868990798
- Sigstore integration time:
-
Permalink:
Convex-Dev/convex-api-py@1811f5cd2d4253268f3136f97f782c0ae14b09b3 -
Branch / Tag:
refs/tags/v0.3.3 - Owner: https://github.com/Convex-Dev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@1811f5cd2d4253268f3136f97f782c0ae14b09b3 -
Trigger Event:
push
-
Statement type: