Skip to main content

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 stack
  • uiua.pop() - Pop a value from the stack and return it as a python object
  • uiua.run(code) - Execute Uiua code on the current stack
  • uiua.stack() - Inspect the stack without modifying it
  • uiua.clear() - Remove all values from the stack
  • len(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

  • rustup (Rust installer)
  • uv (Python package manager)

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


Download files

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

Source Distribution

pyuiua-0.0.1.tar.gz (49.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyuiua-0.0.1-cp313-cp313-macosx_11_0_arm64.whl (8.7 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Hashes for pyuiua-0.0.1.tar.gz
Algorithm Hash digest
SHA256 5e7a2e467c313376939a7e43cafda0aa21229f120f7d3b40b4f0f68b26bc6da5
MD5 d71e1a53862b3926e6a5918fde6330ff
BLAKE2b-256 748968ca2e3cd2bbdfed58637e3738ad7ee2c3bae590c19f6204e11030ca76ec

See more details on using hashes here.

File details

Details for the file pyuiua-0.0.1-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyuiua-0.0.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3c3c343904c9cd0383b6a8ec6515888bc1ad81938644d360bdbb08d4b24f1332
MD5 31106acb875bbb386ad95f4d100e8c02
BLAKE2b-256 d79e6f66618b07241fd71577e609a354d2809ca89ced88bafcc51b23bde43ec3

See more details on using hashes here.

Supported by

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