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

Eval method

import pyuiua

pyuiua.eval("+ 1 2")           # 3
pyuiua.eval("/+", [1, 2, 3])   # 6
pyuiua.eval("/×⇡₁10")          # 3628800 (10 factorial)
pyuiua.eval("∩+", 1, 2, 3, 4)  # (3, 7)

Persisted instance

import pyuiua

uiua = pyuiua.Uiua()

# Push Python values onto the stack and operate on them
uiua.push(10)
uiua.push(20)
uiua.run("+")
print(uiua.pop())  # 30

# Work with arrays
uiua.push([1, 2, 3, 4, 5])
uiua.run("/+")
print(uiua.pop())  # 15

# Inspect the stack
uiua.push(1)
uiua.push(2)
uiua.push(3)
print(uiua.stack())  # [1, 2, 3]
print(len(uiua))     # 3

# Clear the stack
uiua.clear()

API Reference

pyuiua.eval(code, *args) - Run Uiua code with any number of inputs and return the resulting value or tuple or values (or None if no output)

pyuiua.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
  • uiua.run(code) - Execute Uiua code on the current stack
  • uiua.stack() - Return all stack values as a list (without modifying)
  • 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: 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.8.tar.gz (50.2 kB view details)

Uploaded Source

Built Distributions

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

pyuiua-0.0.8-cp310-abi3-win_amd64.whl (10.1 MB view details)

Uploaded CPython 3.10+Windows x86-64

pyuiua-0.0.8-cp310-abi3-win32.whl (8.8 MB view details)

Uploaded CPython 3.10+Windows x86

pyuiua-0.0.8-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (11.0 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ x86-64

pyuiua-0.0.8-cp310-abi3-macosx_11_0_arm64.whl (9.5 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

pyuiua-0.0.8-cp310-abi3-macosx_10_12_x86_64.whl (10.3 MB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

Details for the file pyuiua-0.0.8.tar.gz.

File metadata

  • Download URL: pyuiua-0.0.8.tar.gz
  • Upload date:
  • Size: 50.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.10.2

File hashes

Hashes for pyuiua-0.0.8.tar.gz
Algorithm Hash digest
SHA256 733bbfb51c9f0cb38f9cc20939c45ab1f8168d52863658a9b185e599c78a163d
MD5 ca6f0403c31bec26c96cd7ba92b3a763
BLAKE2b-256 5491ca76bfaea57ceecb4573e086c9764f260ae8f7932b93ff541b20d3ab4e2b

See more details on using hashes here.

File details

Details for the file pyuiua-0.0.8-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: pyuiua-0.0.8-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 10.1 MB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.10.2

File hashes

Hashes for pyuiua-0.0.8-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 9409d3336cd304cce2c1110c54481dfe19ed32f0f3978b1b1914e50afe10da3c
MD5 5b19698435e77f89e7898d6d7091c951
BLAKE2b-256 c2e2945ba66090f728b125fbccd7d8f6b2a7cd481a02662dce13e4f9ab5baf8b

See more details on using hashes here.

File details

Details for the file pyuiua-0.0.8-cp310-abi3-win32.whl.

File metadata

  • Download URL: pyuiua-0.0.8-cp310-abi3-win32.whl
  • Upload date:
  • Size: 8.8 MB
  • Tags: CPython 3.10+, Windows x86
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.10.2

File hashes

Hashes for pyuiua-0.0.8-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 16d0d98475ae596ff57c580db57c315deb38698df0d6bc6bbb2a7320ef2663f7
MD5 ac756f2f64bcf300480c24bfb856a5d0
BLAKE2b-256 764a934eac85ed78477050661fc54f545cc44e8ec2af49f9fc8663626da89443

See more details on using hashes here.

File details

Details for the file pyuiua-0.0.8-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyuiua-0.0.8-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e66715354ab15789c9a5e2654b95260a47322b02c7cc88858cf7b0054ffa422d
MD5 eb89a76a57bc91c71de7a32ce03f8d8d
BLAKE2b-256 0e1baa5d9178dc66765d76ef451ac4f13dc9ebe6a071ab09c5b77f087236d5b3

See more details on using hashes here.

File details

Details for the file pyuiua-0.0.8-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyuiua-0.0.8-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 dbd9c5ce7c7ba526d193c676d2f81193a5f5aa59906a7040c7773ffb5f5e001c
MD5 6bb195778527124270e2df799b90c945
BLAKE2b-256 e743047473e3b4af48c90eb09f96a4e779ee160a0060ee14de5a213020c91dd4

See more details on using hashes here.

File details

Details for the file pyuiua-0.0.8-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for pyuiua-0.0.8-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 7397ca882730ce9c582a46c7ea03c4e5097a6d8e0ae9df37e4061b79c756ffff
MD5 fb48c65d0f19dc44e0d6f184089b5ed2
BLAKE2b-256 ea2f2e7619146aecdad2da4d6c4431f571b783d7cefa8579b9abac0007ddd992

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