Skip to main content

An optimising compiler for Algorand Python

Project description

Algorand Python

Algorand Python is a partial implementation of the Python programming language that runs on the AVM. It includes a statically typed framework for development of Algorand smart contracts and logic signatures, with Pythonic interfaces to underlying AVM functionality that works with standard Python tooling.

Algorand Python is compiled for execution on the AVM by PuyaPy, an optimising compiler that ensures the resulting AVM bytecode execution semantics that match the given Python code. PuyaPy produces output that is directly compatible with AlgoKit typed clients to make deployment and calling easy.

Documentation | Language guide

Installation

Recommended method

The easiest way to use Algorand Python is to instantiate a template with AlgoKit via:

algokit init -t python

This will give you a full development environment with intellisense, linting, automatic formatting, breakpoint debugging, deployment and CI/CD.

A sample smart contract will be placed under PROJECT_NAME/projects/PROJECT_NAME/smart_contracts/SMART_CONTRACT_NAME/contract.py (replacing PROJECT_NAME and SMART_CONTRACT_NAME with the values you chose during the template wizard.)

Manual Alternative

Alternatively, if you want to start from scratch you can do the following:

  1. Ensure you have Python 3.12+
  2. Install AlgoKit CLI
  3. Check you can run the compiler:
    algokit compile py -h
    
  4. Install Algorand Python into your project poetry add algorand-python
  5. Create a contract in a (e.g.) contract.py file:
    from algopy import ARC4Contract, arc4
    class HelloWorldContract(ARC4Contract):
        @arc4.abimethod
        def hello(self, name: arc4.String) -> arc4.String:
            return "Hello, " + name
    

Usage

  1. Navigate to your contract and compile it:
    algokit compile py contract.py
    
  2. You should now have HelloWorldContract.approval.teal and HelloWorldContract.clear.teal on the file system!
  3. We generally recommend using ARC-32 and generated typed clients to have the most optimal deployment and consumption experience; to do this you need to ask PuyaPy to output an ARC-32 compatible app spec file:
    algokit compile py contract.py --output-arc32 --no-output-teal
    
  4. You should now have HelloWorldContract.arc32.json, which can be generated into a client e.g. using AlgoKit CLI:
    algokit generate client HelloWorldContract.arc32.json --output client.py
    
  5. From here you can dive into the examples or look at the documentation.

Examples

There are many examples in this repo, here are some of the more useful ones that showcase what is possible.

The compiled output is available under the out/ directory alongside these, e.g. the approval TEAL for voting is available at examples/voting/out/VotingRoundApp.approval.teal.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

puyapy-3.4.0-py3-none-any.whl (2.3 MB view details)

Uploaded Python 3

File details

Details for the file puyapy-3.4.0-py3-none-any.whl.

File metadata

  • Download URL: puyapy-3.4.0-py3-none-any.whl
  • Upload date:
  • Size: 2.3 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for puyapy-3.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7a46608d831c2cb8e22602fb9bd4b1d221dc1d5239a66fefadeede44e777d250
MD5 12efb7b75eed988f33ff915798d66cdd
BLAKE2b-256 b11e1b3913ade6e7e23e55b29aa54e6dcf57afaec891053b46d735c471913285

See more details on using hashes here.

Supported by

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