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

Certificate verification is enabled by default for security. Verifies responses via BLS12-381 signatures with blst:

# Default: verification enabled
agent.update("canister-id", "method_name", [{'type': Types.Nat, 'value': 2}])

# To disable (for compatibility/testing):
agent.update("canister-id", "method_name", [{'type': Types.Nat, 'value': 2}], verify_certificate=False)

๐Ÿงฉ 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}],
    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], certificate verification enabled by default)
agent.update("wcrzb-2qaaa-aaaap-qhpgq-cai", "set_value", [42])

# 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: v2.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-2.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-2.0.0-py3-none-any.whl (3.2 MB view details)

Uploaded Python 3

File details

Details for the file icp_py_core-2.0.0.tar.gz.

File metadata

  • Download URL: icp_py_core-2.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-2.0.0.tar.gz
Algorithm Hash digest
SHA256 2ee83c483285cf3c6a4e8899f7d158c8832bbcde0ef62f3552a61af3feb54200
MD5 fc8f18369b0b633022364a0782b32ccd
BLAKE2b-256 b11e6dcd5018b664f0da4b5304a1211b7cb25d6da2f7066a8608f396cc42a6a0

See more details on using hashes here.

File details

Details for the file icp_py_core-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: icp_py_core-2.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-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 43959708eb71df48bf68ab439e0c3698dceac3d8fd488dea41a3f8a4bf40477d
MD5 fee8997e01c358d8a06eb5b46d6e7a92
BLAKE2b-256 00a1510c6cab5274345a31f9f07e7ce98c16421c6bc58a38fc421390dd26a0bd

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