Skip to main content

Core Python SDK for the Internet Computer: agent, candid, identity, principal, certificate.

Project description

๐Ÿ ICP-PY-CORE

ICP-PY-CORE Logo

PyPI version License: MIT Internet Computer


๐Ÿ“– 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() and Agent.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

  1. ๐Ÿงฉ Candid encode & decode
  2. ๐Ÿ” ed25519 & secp256k1 identities
  3. ๐Ÿงพ Principal utilities (strict DER mode)
  4. โš™๏ธ High-level canister calls via Agent
  5. ๐Ÿช™ Support for Ledger / Governance / Management / Cycles Wallet
  6. ๐Ÿ” 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 the icp_core facade)
  • 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

icp_py_core-1.0.0.tar.gz (3.2 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

icp_py_core-1.0.0-py3-none-any.whl (3.2 MB view details)

Uploaded Python 3

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

Hashes for icp_py_core-1.0.0.tar.gz
Algorithm Hash digest
SHA256 175de8ac866217f4bd01d728dc34bdb96c03a01c3427a73598311ccaa0c3513b
MD5 029e7e10350288dcecb5c694a37e8c67
BLAKE2b-256 97d5f3d201dd67391b6296f028ff1d224a4e0817dcd292f5445f1b16a8b80385

See more details on using hashes here.

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

Hashes for icp_py_core-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c8cacf2ec4cd029bb9eeabbba71d677e54155fc3e34d2be203823666273aca77
MD5 a505c5caf32bcf71892100477827309d
BLAKE2b-256 f54b8fabf4d3bee947d0338104880c7987b8ce324b2611d7ade4660d0d794b8a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page