Skip to content

eliezhao/icp-py-core

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

19 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🐍 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.

About

Python Agent Library for the DFINITY Internet Computer

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages