https://github.com/opshin/pyaiken
Python bindings for aiken
https://github.com/opshin/pyaiken
Last synced: 12 months ago
JSON representation
Python bindings for aiken
- Host: GitHub
- URL: https://github.com/opshin/pyaiken
- Owner: OpShin
- License: mit
- Created: 2023-01-12T16:11:21.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2024-01-01T22:45:48.000Z (over 2 years ago)
- Last Synced: 2025-02-13T13:15:21.598Z (over 1 year ago)
- Language: Rust
- Size: 36.1 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
pyaiken
=======
[](https://github.com/OpShin/pyaiken/actions/workflows/CI.yml)
[](https://app.travis-ci.com/OpShin/pyaiken)
[](https://pypi.org/project/pyaiken/)
[](https://pypi.org/project/pyaiken/)
This package supplies python bindings for the package [aiken](https://github.com/aiken-lang/aiken).
The bindings are added on a per-need basis, currently only serving the development of [opshin](https://github.com/opshin)
### Installation
Install python3. Then run the following command.
```bash
python3 -m pip install pyaiken
```
### Usage
```python
from pyaiken import uplc
# Tools for handling UPLC
### uplc.flat
# Print the hex of the CBOR encoded flat-encoding of the program in UPLC textual notation
code = uplc.flat("(program 1.0.0 (con data #01))")
print(code)
# prints "490100004c0101010001"
### uplc.unflat
# Print the UPLC in textual notation from the hex of the CBOR encoded flat-encoding
code = uplc.unflat("490100004c0101010001")
print(code)
# prints "(program 1.0.0 (con data #01))"
### uplc.eval
# Evaluate a UPLC program with the given arguments (all in textual representation) and cpu and memory budget (optional, in this order)
# Returns either computed UPLC value on success or thrown error on failure,
# logs generated through trace
# and the consumed cpu and memory steps
((suc, err), logs, (cpu, mem)) = uplc.eval("(program 1.0.0 (lam x x))", ["(con data #01)"], 1000000, None)
print((suc, err), logs, (cpu, mem))
# prints "('(con data #01)', None), [], (92100, 500)"
```
### Building
In case you need to build this package from source, install Python3 and Rust and proceed as follows.
```bash
git clone https://github.com/OpShin/pyaiken
cd pyaiken
python3 -m venv .env
source .env/bin/activate # or in whichever environment you want to have it installed
pip install maturin
maturin build
```
The package will be installed in the active python environment.