Core Python SDK for the Internet Computer: agent, candid, identity, principal, certificate.
Project description
๐ ICP-PY-CORE
๐ About This Project
ICP-PY-CORE is a maintained and extended fork of ic-py.
This version introduces a modular architecture, protocol upgrades, and new APIs while preserving compatibility with the IC ecosystem.
Highlights:
- โ
Modular structure under
src/(icp_agent,icp_identity,icp_candid, etc.) - โ
Updated boundary node v3 endpoints (
/api/v3/canister/.../call) - โ
Optional certificate verification via
blst - โ Type-safe Candid encoding/decoding
- โ
Pythonic high-level
Agent.update()andAgent.query()methods
๐ Special thanks to the original ic-py author for their foundational work.
๐ง Installation
pip install icp-py-core
If you use the Candid parser, we pin
antlr4-python3-runtime==4.9.3.
For optional certificate verification, see the blst section below.
๐ Key Improvements
โณ๏ธ Modular Codebase
Each component is isolated for clarity and extensibility:
src/
โโโ icp_agent/ # Agent & HTTP Client
โโโ icp_identity/ # ed25519 / secp256k1 identities
โโโ icp_candid/ # Candid encoder/decoder
โโโ icp_principal/ # Principal utilities
โโโ icp_certificate/ # Certificate validation
โโโ icp_core/ # Unified facade (one-line import)
๐ Unified Facade (icp_core)
Import everything from a single entrypoint:
from icp_core import (
Agent, Client,
Identity, DelegateIdentity,
Principal, Certificate,
encode, decode, Types,
)
โก Endpoint Upgrade
All update calls now target Boundary Node v3 endpoints:
/api/v3/canister/<canister_id>/call
๐ Certificate Verification
Enable verifiable responses via BLS12-381 signatures with blst:
agent.update("canister-id", "method_name", [{'type': Types.Nat, 'value': 2}], verify_certificate=True)
๐งฉ Example Usage
Identity
from icp_core import Identity
iden = Identity(privkey="833fe62409237b9d62ec77587520911e9a759cec1d19755b7da901b96dca3d42")
print(iden.sender().to_str())
Client & Agent
from icp_core import Agent, Client, Identity
iden = Identity()
client = Client("https://ic0.app")
agent = Agent(iden, client)
Update (auto-encode)
from icp_core import Types
result = agent.update(
"wcrzb-2qaaa-aaaap-qhpgq-cai",
"set",
[{'type': Types.Nat, 'value': 2}],
verify_certificate=True,
return_type=[Types.Nat],
)
Query (auto-encode empty args)
reply = agent.query("wcrzb-2qaaa-aaaap-qhpgq-cai", "get", [])
print(reply)
๐ Installing blst (optional)
macOS / Linux
git clone https://github.com/supranational/blst
cd blst/bindings/python
# For Apple Silicon (if needed)
# export BLST_PORTABLE=1
python3 run.me
export PYTHONPATH="$PWD:$PYTHONPATH"
Or copy to site-packages manually:
BLST_SRC="/path/to/blst/bindings/python"
PYBIN="python3"
SITE_PURE="$($PYBIN -c 'import sysconfig; print(sysconfig.get_paths()[\\"purelib\\"])')"
SITE_PLAT="$($PYBIN -c 'import sysconfig; print(sysconfig.get_paths()[\\"platlib\\"])')"
cp "$BLST_SRC/blst.py" "$SITE_PURE"/
cp "$BLST_SRC"/_blst*.so "$SITE_PLAT"/
Windows
Use WSL2 (Ubuntu) for best compatibility.
๐ง Features
- ๐งฉ Candid encode & decode
- ๐ ed25519 & secp256k1 identities
- ๐งพ Principal utilities (strict DER mode)
- โ๏ธ High-level canister calls via Agent
- ๐ช Support for Ledger / Governance / Management / Cycles Wallet
- ๐ Sync & async APIs
๐งฐ Example โ End-to-End
from icp_core import Agent, Client, Identity, Types
client = Client("https://ic0.app")
iden = Identity()
agent = Agent(iden, client)
# Update (auto-encode [42])
agent.update("wcrzb-2qaaa-aaaap-qhpgq-cai", "set_value", [42], verify_certificate=True)
# Query (auto-encode empty args)
res = agent.query("wcrzb-2qaaa-aaaap-qhpgq-cai", "get_value", None, return_type=[Types.Nat])
print(res)
๐ Migration
Migrating from ic-py? See MIGRATION.md for:
- New package layout (
icp_*subpackages and theicp_corefacade) - Endpoint changes (v3 call)
- Argument auto-encoding in
Agent.update()/Agent.query() - Certificate verification flag
๐ Changelog
We maintain release notes on GitHub Releases:
https://github.com/eliezhao/icp-py-core/releases
๐บ Roadmap
See ROADMAP.md
โ
Milestone 1: v3 endpoint migration & polling stability
โ
Milestone 2: Certificate verification with blst
๐ Milestone 3: ICRC utilities, Candid enhancements, type reflection
๐ Version
- Current release: v1.0.0
๐ Acknowledgments
Special thanks to the IC community and contributors to the original ic-py.
icp-py-core continues this legacy with modern Python standards and long-term maintenance.
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
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 icp_py_core-1.0.0.tar.gz.
File metadata
- Download URL: icp_py_core-1.0.0.tar.gz
- Upload date:
- Size: 3.2 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
175de8ac866217f4bd01d728dc34bdb96c03a01c3427a73598311ccaa0c3513b
|
|
| MD5 |
029e7e10350288dcecb5c694a37e8c67
|
|
| BLAKE2b-256 |
97d5f3d201dd67391b6296f028ff1d224a4e0817dcd292f5445f1b16a8b80385
|
File details
Details for the file icp_py_core-1.0.0-py3-none-any.whl.
File metadata
- Download URL: icp_py_core-1.0.0-py3-none-any.whl
- Upload date:
- Size: 3.2 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c8cacf2ec4cd029bb9eeabbba71d677e54155fc3e34d2be203823666273aca77
|
|
| MD5 |
a505c5caf32bcf71892100477827309d
|
|
| BLAKE2b-256 |
f54b8fabf4d3bee947d0338104880c7987b8ce324b2611d7ade4660d0d794b8a
|