Skip to main content

Python

Beginner
Python

Python is a general-purpose, high-level programming language that is designed for widespread flexibility, functionality, and increased code readability. It supports structured, functional, and object-orientated programming.

To develop Python smart contracts on ICP, the canister development kit (CDK) known as Kybra can be used.

Kybra is designed as a fully comprehensive Python environment for ICP canisters. It supports as many relevant environment APIs as possible.

Kybra allows developers to bring their existing Python skills and workflows to ICP, such as using pip packages.

Kybra is a community contributed project and is not maintained by DFINITY. Kybra is developed by Demergent Labs, a for-profit company that receives a grant from DFINITY for development of Kybra.

Using Kybra

To use Kybra:

  • It is highly recommended that dfx commands should be run in a Python virtual environment that contains the kybra package.

  • The virtual environment must use the following dependencies and the exact versions listed:

    • dfx v0.23.0 or newer.

    • Python v3.10.7

To set up a Python virtual environment and install Kybra, use the following commands:

curl https://pyenv.run | bash
~/.pyenv/bin/pyenv install 3.10.7
~/.pyenv/versions/3.10.7/bin/python -m venv venv
source venv/bin/activate
pip install kybra

Documentation