Python bindings for the Uiua programming language.
Project description
PyUiua
A Python binding for Uiua, allowing interaction between Uiua and Python.
Requirements
- Python 3.10 or higher
Installation
pip install pyuiua
or see dev setup below for building from source
Example Usage
Basic Usage
import pyuiua
# Create a Uiua instance
uiua = pyuiua.Uiua()
# Basic evaluation - run code and pop result
uiua.run("/×⇡₁10") # Calculate 10 factorial
print(uiua.pop()) # 3628800
# Push Python values onto the stack
uiua.push(10)
uiua.push(20)
uiua.run("+") # Then run a Uiua operation
print(uiua.pop()) # 30
# Work with arrays
uiua.push([1, 2, 3, 4, 5])
uiua.run("/+") # Sum the array
print(uiua.pop()) # 15
# Inspect the stack without modifying it
uiua.push(1)
uiua.push(2)
uiua.push(3)
print(uiua.stack()) # [3, 2, 1]
print(len(uiua)) # 3
# Clear the stack
uiua.clear()
API Reference
Uiua() - Create a Uiua instance
uiua.push(value)- Push a Python value onto the stackuiua.pop()- Pop a value from the stack and return it as a python objectuiua.run(code)- Execute Uiua code on the current stackuiua.stack()- Inspect the stack without modifying ituiua.clear()- Remove all values from the stacklen(uiua)- Get the number of values on the stack
Type Conversions
The conversion of types is currently lossy. Both arrays and boxes convert to lists in Python, and Python lists convert to an array if they're homogeneous with a well-defined shape, otherwise a box. As a result, a box in Uiua of homogeneous values will become an array when converted to python and back.
- Currently supports: most scalars, multidimensional arrays, and boxed arrays
- Does not yet support: complex numbers, maps, functions, or user-defined types
Uiua → Python
| Uiua Type | Python Type |
|---|---|
| Scalar number | int or float |
| Scalar char | str |
| Scalar byte | int |
| 1D Array | list |
| Multi-dimensional Array | Nested list |
| Box Array (heterogeneous) | list |
Python → Uiua
| Python Type | Uiua Type |
|---|---|
int |
Scalar number |
float |
Scalar number |
str |
Character array/string |
list (homogeneous) |
Array |
list (heterogeneous) |
Box Array |
Development
Requirements
Set-up
# Clone
git clone https://github.com/KatieLG/python-uiua.git
cd python-uiua
# Install dependencies
uv sync
# Build and install
uv run maturin develop
Dev Commands
| Command | Purpose |
|---|---|
make dev |
Rebuild after making changes to Rust code |
make test |
Run unit tests |
make lint |
Run linters and type checkers |
make format |
Auto-format code |
make check |
Format, lint, and test |
make build |
Build wheel for distribution |
make test-release |
Publish to TestPyPI |
make release |
Publish to PyPI |
Links
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyuiua-0.0.1.tar.gz.
File metadata
- Download URL: pyuiua-0.0.1.tar.gz
- Upload date:
- Size: 49.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5e7a2e467c313376939a7e43cafda0aa21229f120f7d3b40b4f0f68b26bc6da5
|
|
| MD5 |
d71e1a53862b3926e6a5918fde6330ff
|
|
| BLAKE2b-256 |
748968ca2e3cd2bbdfed58637e3738ad7ee2c3bae590c19f6204e11030ca76ec
|
File details
Details for the file pyuiua-0.0.1-cp313-cp313-macosx_11_0_arm64.whl.
File metadata
- Download URL: pyuiua-0.0.1-cp313-cp313-macosx_11_0_arm64.whl
- Upload date:
- Size: 8.7 MB
- Tags: CPython 3.13, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3c3c343904c9cd0383b6a8ec6515888bc1ad81938644d360bdbb08d4b24f1332
|
|
| MD5 |
31106acb875bbb386ad95f4d100e8c02
|
|
| BLAKE2b-256 |
d79e6f66618b07241fd71577e609a354d2809ca89ced88bafcc51b23bde43ec3
|