pyuiua 0.0.2__cp313-cp313-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
py.typed ADDED
File without changes
pyuiua/__init__.py ADDED
@@ -0,0 +1,5 @@
1
+ from .pyuiua import *
2
+
3
+ __doc__ = pyuiua.__doc__
4
+ if hasattr(pyuiua, "__all__"):
5
+ __all__ = pyuiua.__all__
pyuiua/__init__.pyi ADDED
@@ -0,0 +1,197 @@
1
+ """Python bindings for the Uiua programming language.
2
+
3
+ Supports executing Uiua code from python and manipulating the stack in either language.
4
+ Values are automatically converted between Python and Uiua types.
5
+
6
+ Example:
7
+ >>> from pyuiua import Uiua
8
+ >>> uiua = Uiua()
9
+ >>> uiua.run("+ 1 2")
10
+ >>> uiua.pop()
11
+ 3
12
+ """
13
+
14
+ from typing import TypeAlias
15
+
16
+ UiuaValue: TypeAlias = int | float | str | list["UiuaValue"]
17
+ """Type representing the values that pyuiua supports for python <-> uiua conversion.
18
+
19
+ Can be:
20
+
21
+ - int: (converts to Uiua Num/f64)
22
+
23
+ - float: (converts to Uiua Num/f64)
24
+
25
+ - str: (converts to a Uiua Char array)
26
+
27
+ - list: lists for flat or multi-dimensional arrays
28
+
29
+ Mixed int/float lists are converted to a float array in Uiua.
30
+ """
31
+
32
+ class UiuaError(RuntimeError):
33
+ """Exception raised when Uiua operations fail, such as:
34
+
35
+ - Syntax errors in Uiua code passed to `run()`
36
+ - Runtime errors during Uiua code execution
37
+ - Calling `pop()` on an empty stack
38
+
39
+ Example:
40
+ >>> u = Uiua()
41
+ >>> u.run("+ 1") # Missing second argument
42
+ UiuaError: ...
43
+ >>> u.pop() # Empty stack
44
+ UiuaError: ...
45
+ """
46
+
47
+ class Uiua:
48
+ """A Uiua instance with a persistent stack.
49
+
50
+ The Uiua class provides a Python interface to the Uiua language.
51
+ It maintains a stack that persists between operations, allowing:
52
+ - Pushing Python values onto the stack
53
+ - Executing Uiua code that manipulates the stack
54
+ - Pop results back to Python
55
+
56
+ Example:
57
+ >>> u = Uiua()
58
+ >>> u.push([1, 2, 3, 4, 5])
59
+ >>> u.run("/+") # Sum the array
60
+ >>> u.pop()
61
+ 15
62
+ """
63
+
64
+ def __init__(self) -> None:
65
+ """Create a new Uiua interpreter with an empty stack.
66
+
67
+ Example:
68
+ >>> u = Uiua()
69
+ >>> len(u)
70
+ 0
71
+ """
72
+ ...
73
+
74
+ def push(self, value: UiuaValue) -> None:
75
+ """Push a Python value onto the Uiua stack.
76
+
77
+ Args:
78
+ value: A Python value to push.
79
+
80
+ Raises:
81
+ TypeError: If the value cannot be converted to a Uiua type.
82
+
83
+ Example:
84
+ >>> u = Uiua()
85
+ >>> u.push(42)
86
+ >>> u.push([1, 2, 3])
87
+ >>> len(u)
88
+ >>> u.stack()
89
+ 2
90
+ [[1, 2, 3], 42]
91
+ """
92
+ ...
93
+
94
+ def pop(self) -> UiuaValue:
95
+ """Pop the top value from the stack and convert to a Python object.
96
+
97
+ Returns:
98
+ The top value from the stack as a Python value.
99
+
100
+ Raises:
101
+ UiuaError: If the stack is empty.
102
+
103
+ Example:
104
+ >>> u = Uiua()
105
+ >>> u.push(42)
106
+ >>> u.pop()
107
+ 42
108
+ >>> u.pop() # Stack is empty
109
+ UiuaError: Failed to pop from stack: No values on stack
110
+ """
111
+ ...
112
+
113
+ def stack(self) -> list[UiuaValue]:
114
+ """Return all values on the stack as a Python list.
115
+
116
+ Returns with the bottom of the stack at index 0 and the top at the end. The stack is not modified.
117
+
118
+ Returns:
119
+ A list containing all stack values, bottom to top.
120
+
121
+ Example:
122
+ >>> u = Uiua()
123
+ >>> u.push(1)
124
+ >>> u.push(2)
125
+ >>> u.push(3)
126
+ >>> u.stack()
127
+ [1, 2, 3]
128
+ """
129
+ ...
130
+
131
+ def run(self, code: str) -> None:
132
+ """Execute Uiua code
133
+
134
+ Runs the provided Uiua code, which has access to use and modify the current stack.
135
+
136
+ Args:
137
+ code: A string containing Uiua code to execute.
138
+
139
+ Raises:
140
+ UiuaError: If the code contains syntax errors or runtime errors.
141
+
142
+ Example:
143
+ >>> u = Uiua()
144
+ >>> u.push(5)
145
+ >>> u.push(3)
146
+ >>> u.run("+") # Add top two values
147
+ >>> u.pop()
148
+ 8
149
+ """
150
+ ...
151
+
152
+ def clear(self) -> None:
153
+ """Remove all values from the stack.
154
+
155
+ Example:
156
+ >>> u = Uiua()
157
+ >>> u.push(1)
158
+ >>> u.push(2)
159
+ >>> u.clear()
160
+ >>> len(u)
161
+ 0
162
+ """
163
+ ...
164
+
165
+ def __len__(self) -> int:
166
+ """Get the number of values on the stack.
167
+
168
+ Returns:
169
+ The number of values currently on the stack.
170
+
171
+ Example:
172
+ >>> u = Uiua()
173
+ >>> len(u)
174
+ 0
175
+ >>> u.push(1)
176
+ >>> len(u)
177
+ 1
178
+ """
179
+ ...
180
+
181
+ def __repr__(self) -> str:
182
+ """Generates a string representation of the Uiua instance.
183
+
184
+ Returns:
185
+ A string showing the current stack state
186
+
187
+ Example:
188
+ >>> u = Uiua()
189
+ >>> repr(u)
190
+ 'Uiua(stack=[])'
191
+ >>> u.push(42)
192
+ >>> repr(u)
193
+ 'Uiua(stack=[42])'
194
+ """
195
+ ...
196
+
197
+ __all__ = ["Uiua", "UiuaError", "UiuaValue"]
pyuiua/py.typed ADDED
File without changes
Binary file
@@ -0,0 +1,158 @@
1
+ Metadata-Version: 2.4
2
+ Name: pyuiua
3
+ Version: 0.0.2
4
+ Classifier: Development Status :: 4 - Beta
5
+ Classifier: Intended Audience :: Developers
6
+ Classifier: License :: OSI Approved :: MIT License
7
+ Classifier: Programming Language :: Rust
8
+ Classifier: Programming Language :: Python
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3.10
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Classifier: Programming Language :: Python :: 3.13
14
+ Classifier: Programming Language :: Python :: Implementation :: CPython
15
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
16
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
17
+ Classifier: Topic :: Software Development :: Interpreters
18
+ Classifier: Typing :: Typed
19
+ License-File: LICENSE
20
+ Summary: Python bindings for the Uiua programming language.
21
+ Keywords: uiua,array-programming,python-bindings,interpreter
22
+ Author: Katie Gardner
23
+ Requires-Python: >=3.10
24
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
25
+
26
+ # PyUiua
27
+
28
+ A Python binding for [Uiua](https://www.uiua.org/), allowing interaction between Uiua and Python.
29
+
30
+ ## Requirements
31
+
32
+ - Python 3.10 or higher
33
+
34
+ ## Installation
35
+
36
+ ```bash
37
+ pip install pyuiua
38
+ ```
39
+
40
+ or see dev setup below for building from source
41
+
42
+ ## Example Usage
43
+
44
+ ### Basic Usage
45
+
46
+ ```python
47
+ import pyuiua
48
+
49
+ # Create a Uiua instance
50
+ uiua = pyuiua.Uiua()
51
+
52
+ # Basic evaluation - run code and pop result
53
+ uiua.run("/×⇡₁10") # Calculate 10 factorial
54
+ print(uiua.pop()) # 3628800
55
+
56
+ # Push Python values onto the stack
57
+ uiua.push(10)
58
+ uiua.push(20)
59
+ uiua.run("+") # Then run a Uiua operation
60
+ print(uiua.pop()) # 30
61
+
62
+ # Work with arrays
63
+ uiua.push([1, 2, 3, 4, 5])
64
+ uiua.run("/+") # Sum the array
65
+ print(uiua.pop()) # 15
66
+
67
+ # Inspect the stack without modifying it
68
+ uiua.push(1)
69
+ uiua.push(2)
70
+ uiua.push(3)
71
+ print(uiua.stack()) # [3, 2, 1]
72
+ print(len(uiua)) # 3
73
+
74
+ # Clear the stack
75
+ uiua.clear()
76
+ ```
77
+
78
+ ## API Reference
79
+
80
+ **`Uiua()`** - Create a Uiua instance
81
+
82
+ - `uiua.push(value)` - Push a Python value onto the stack
83
+ - `uiua.pop()` - Pop a value from the stack and return it as a python object
84
+ - `uiua.run(code)` - Execute Uiua code on the current stack
85
+ - `uiua.stack()` - Inspect the stack without modifying it
86
+ - `uiua.clear()` - Remove all values from the stack
87
+ - `len(uiua)` - Get the number of values on the stack
88
+
89
+ ## Type Conversions
90
+
91
+ The conversion of types is currently lossy. Both arrays and boxes convert to lists in Python, and Python lists convert
92
+ to an array if they're homogeneous with a well-defined shape, otherwise a box. As a result, a box in Uiua of homogeneous
93
+ values will become an array when converted to python and back.
94
+
95
+ - **Currently supports**: most scalars, multidimensional arrays, and boxed arrays
96
+ - **Does not yet support**: complex numbers, maps, functions, or user-defined types
97
+
98
+ ### Uiua → Python
99
+
100
+ | Uiua Type | Python Type |
101
+ | ------------------------- | ---------------- |
102
+ | Scalar number | `int` or `float` |
103
+ | Scalar char | `str` |
104
+ | Scalar byte | `int` |
105
+ | 1D Array | `list` |
106
+ | Multi-dimensional Array | Nested `list` |
107
+ | Box Array (heterogeneous) | `list` |
108
+
109
+ ### Python → Uiua
110
+
111
+ | Python Type | Uiua Type |
112
+ | ---------------------- | ---------------------- |
113
+ | `int` | Scalar number |
114
+ | `float` | Scalar number |
115
+ | `str` | Character array/string |
116
+ | `list` (homogeneous) | Array |
117
+ | `list` (heterogeneous) | Box Array |
118
+
119
+ ## Development
120
+
121
+ ### Requirements
122
+
123
+ - [rustup](https://rustup.rs/) (Rust installer)
124
+ - [uv](https://github.com/astral-sh/uv) (Python package manager)
125
+
126
+ ### Set-up
127
+
128
+ ```bash
129
+ # Clone
130
+ git clone https://github.com/KatieLG/python-uiua.git
131
+ cd python-uiua
132
+
133
+ # Install dependencies
134
+ uv sync
135
+
136
+ # Build and install
137
+ uv run maturin develop
138
+ ```
139
+
140
+ ### Dev Commands
141
+
142
+ | Command | Purpose |
143
+ | ------------------- | ----------------------------------------- |
144
+ | `make dev` | Rebuild after making changes to Rust code |
145
+ | `make test` | Run unit tests |
146
+ | `make lint` | Run linters and type checkers |
147
+ | `make format` | Auto-format code |
148
+ | `make check` | Format, lint, and test |
149
+ | `make build` | Build wheel for distribution |
150
+ | `make test-release` | Publish to TestPyPI |
151
+ | `make release` | Publish to PyPI |
152
+
153
+ ## Links
154
+
155
+ - [Uiua Language](https://www.uiua.org/)
156
+ - [PyO3 Documentation](https://pyo3.rs/)
157
+ - [Maturin Documentation](https://www.maturin.rs/)
158
+
@@ -0,0 +1,10 @@
1
+ py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ pyuiua-0.0.2.dist-info/METADATA,sha256=Ei4eZvOBLdAlD7dTkFkJ6KVX3VU3ukI8Oo5WFWGdMgg,4980
3
+ pyuiua-0.0.2.dist-info/WHEEL,sha256=lraoTyulw0EpTbLV2AtR5kXAJRP7w3nUqalBgpOHvcQ,97
4
+ pyuiua-0.0.2.dist-info/licenses/LICENSE,sha256=vCK6e9eP9LUtSn_0d22ZSunu-nnNEAOYDvIeW9_75dg,1091
5
+ pyuiua.pyi,sha256=dL4zcAnootPvNuqRY9oXAhR6j9xvTPAMhYU-XY8u1NA,5022
6
+ pyuiua/__init__.py,sha256=XQITSQw6461dHAb7dq5kOLlkqP3IDXPwLRblQjL37zE,107
7
+ pyuiua/__init__.pyi,sha256=dL4zcAnootPvNuqRY9oXAhR6j9xvTPAMhYU-XY8u1NA,5022
8
+ pyuiua/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
+ pyuiua/pyuiua.cp313-win_amd64.pyd,sha256=k9nGxU2V2Kq1FEjgxwqaAOZGfbQLrnfphf_A9wC_iv4,27466240
10
+ pyuiua-0.0.2.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: maturin (1.10.2)
3
+ Root-Is-Purelib: false
4
+ Tag: cp313-cp313-win_amd64
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Katie Gardner
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
pyuiua.pyi ADDED
@@ -0,0 +1,197 @@
1
+ """Python bindings for the Uiua programming language.
2
+
3
+ Supports executing Uiua code from python and manipulating the stack in either language.
4
+ Values are automatically converted between Python and Uiua types.
5
+
6
+ Example:
7
+ >>> from pyuiua import Uiua
8
+ >>> uiua = Uiua()
9
+ >>> uiua.run("+ 1 2")
10
+ >>> uiua.pop()
11
+ 3
12
+ """
13
+
14
+ from typing import TypeAlias
15
+
16
+ UiuaValue: TypeAlias = int | float | str | list["UiuaValue"]
17
+ """Type representing the values that pyuiua supports for python <-> uiua conversion.
18
+
19
+ Can be:
20
+
21
+ - int: (converts to Uiua Num/f64)
22
+
23
+ - float: (converts to Uiua Num/f64)
24
+
25
+ - str: (converts to a Uiua Char array)
26
+
27
+ - list: lists for flat or multi-dimensional arrays
28
+
29
+ Mixed int/float lists are converted to a float array in Uiua.
30
+ """
31
+
32
+ class UiuaError(RuntimeError):
33
+ """Exception raised when Uiua operations fail, such as:
34
+
35
+ - Syntax errors in Uiua code passed to `run()`
36
+ - Runtime errors during Uiua code execution
37
+ - Calling `pop()` on an empty stack
38
+
39
+ Example:
40
+ >>> u = Uiua()
41
+ >>> u.run("+ 1") # Missing second argument
42
+ UiuaError: ...
43
+ >>> u.pop() # Empty stack
44
+ UiuaError: ...
45
+ """
46
+
47
+ class Uiua:
48
+ """A Uiua instance with a persistent stack.
49
+
50
+ The Uiua class provides a Python interface to the Uiua language.
51
+ It maintains a stack that persists between operations, allowing:
52
+ - Pushing Python values onto the stack
53
+ - Executing Uiua code that manipulates the stack
54
+ - Pop results back to Python
55
+
56
+ Example:
57
+ >>> u = Uiua()
58
+ >>> u.push([1, 2, 3, 4, 5])
59
+ >>> u.run("/+") # Sum the array
60
+ >>> u.pop()
61
+ 15
62
+ """
63
+
64
+ def __init__(self) -> None:
65
+ """Create a new Uiua interpreter with an empty stack.
66
+
67
+ Example:
68
+ >>> u = Uiua()
69
+ >>> len(u)
70
+ 0
71
+ """
72
+ ...
73
+
74
+ def push(self, value: UiuaValue) -> None:
75
+ """Push a Python value onto the Uiua stack.
76
+
77
+ Args:
78
+ value: A Python value to push.
79
+
80
+ Raises:
81
+ TypeError: If the value cannot be converted to a Uiua type.
82
+
83
+ Example:
84
+ >>> u = Uiua()
85
+ >>> u.push(42)
86
+ >>> u.push([1, 2, 3])
87
+ >>> len(u)
88
+ >>> u.stack()
89
+ 2
90
+ [[1, 2, 3], 42]
91
+ """
92
+ ...
93
+
94
+ def pop(self) -> UiuaValue:
95
+ """Pop the top value from the stack and convert to a Python object.
96
+
97
+ Returns:
98
+ The top value from the stack as a Python value.
99
+
100
+ Raises:
101
+ UiuaError: If the stack is empty.
102
+
103
+ Example:
104
+ >>> u = Uiua()
105
+ >>> u.push(42)
106
+ >>> u.pop()
107
+ 42
108
+ >>> u.pop() # Stack is empty
109
+ UiuaError: Failed to pop from stack: No values on stack
110
+ """
111
+ ...
112
+
113
+ def stack(self) -> list[UiuaValue]:
114
+ """Return all values on the stack as a Python list.
115
+
116
+ Returns with the bottom of the stack at index 0 and the top at the end. The stack is not modified.
117
+
118
+ Returns:
119
+ A list containing all stack values, bottom to top.
120
+
121
+ Example:
122
+ >>> u = Uiua()
123
+ >>> u.push(1)
124
+ >>> u.push(2)
125
+ >>> u.push(3)
126
+ >>> u.stack()
127
+ [1, 2, 3]
128
+ """
129
+ ...
130
+
131
+ def run(self, code: str) -> None:
132
+ """Execute Uiua code
133
+
134
+ Runs the provided Uiua code, which has access to use and modify the current stack.
135
+
136
+ Args:
137
+ code: A string containing Uiua code to execute.
138
+
139
+ Raises:
140
+ UiuaError: If the code contains syntax errors or runtime errors.
141
+
142
+ Example:
143
+ >>> u = Uiua()
144
+ >>> u.push(5)
145
+ >>> u.push(3)
146
+ >>> u.run("+") # Add top two values
147
+ >>> u.pop()
148
+ 8
149
+ """
150
+ ...
151
+
152
+ def clear(self) -> None:
153
+ """Remove all values from the stack.
154
+
155
+ Example:
156
+ >>> u = Uiua()
157
+ >>> u.push(1)
158
+ >>> u.push(2)
159
+ >>> u.clear()
160
+ >>> len(u)
161
+ 0
162
+ """
163
+ ...
164
+
165
+ def __len__(self) -> int:
166
+ """Get the number of values on the stack.
167
+
168
+ Returns:
169
+ The number of values currently on the stack.
170
+
171
+ Example:
172
+ >>> u = Uiua()
173
+ >>> len(u)
174
+ 0
175
+ >>> u.push(1)
176
+ >>> len(u)
177
+ 1
178
+ """
179
+ ...
180
+
181
+ def __repr__(self) -> str:
182
+ """Generates a string representation of the Uiua instance.
183
+
184
+ Returns:
185
+ A string showing the current stack state
186
+
187
+ Example:
188
+ >>> u = Uiua()
189
+ >>> repr(u)
190
+ 'Uiua(stack=[])'
191
+ >>> u.push(42)
192
+ >>> repr(u)
193
+ 'Uiua(stack=[42])'
194
+ """
195
+ ...
196
+
197
+ __all__ = ["Uiua", "UiuaError", "UiuaValue"]