Python bindings for fiasto - A language-agnostic modern Wilkinson's formula parser and lexer
Project description
fiasto-py
Python bindings for fiasto - A language-agnostic modern Wilkinson's formula parser and lexer.
🎯 Features
- Parse Wilkinson's Formulas: Convert formula strings into structured JSON metadata
- Tokenize Formulas: Break down formulas into individual tokens with detailed information
- High Performance: Built with Rust and PyO3 for maximum speed
- Python Dictionaries: Returns native Python dictionaries for easy integration
🚀 Quick Start
Installation
-
Install from PyPI (recommended):
pip install fiasto-py
-
Build from source (for development):
# Install maturin if you haven't already pip install maturin # Build and install in development mode # Note: For Python 3.13, use the forward compatibility flag PYO3_USE_ABI3_FORWARD_COMPATIBILITY=1 maturin develop
-
Or use the build script:
python build.py
Usage
import fiasto_py
# Parse a formula into structured metadata
result = fiasto_py.parse_formula("y ~ x1 + x2 + (1|group)")
print(result)
# Tokenize a formula
tokens = fiasto_py.lex_formula("y ~ x1 * x2 + s(z)")
print(tokens)
Example
import fiasto_py
import json
# Parse a complex mixed-effects formula
formula = "y ~ x1 * x2 + s(z) + (1+x1|group)"
parsed = fiasto_py.parse_formula(formula)
# Pretty print the result
print(json.dumps(parsed, indent=2))
# Tokenize the same formula
tokens = fiasto_py.lex_formula(formula)
print(json.dumps(tokens, indent=2))
📋 Supported Formula Syntax
fiasto supports comprehensive Wilkinson's notation including:
- Basic formulas:
y ~ x1 + x2 - Interactions:
y ~ x1 * x2 - Smooth terms:
y ~ s(z) - Random effects:
y ~ x + (1|group) - Complex random effects:
y ~ x + (1+x|group) - Multivariate models:
mvbind(y1, y2) ~ x + (1|g) - Non-linear models:
y ~ a1 - a2^x, a1 ~ 1, a2 ~ x + (x|g), nl = TRUE
For the complete syntax reference, see the fiasto documentation.
🛠️ Development
Prerequisites
- Python 3.8+
- Rust (latest stable)
- maturin
Building
# Development build (with Python 3.13 compatibility)
PYO3_USE_ABI3_FORWARD_COMPATIBILITY=1 maturin develop
# Release build
PYO3_USE_ABI3_FORWARD_COMPATIBILITY=1 maturin build --release
# Run tests
python example.py
Project Structure
fiasto-py/
├── src/
│ └── lib.rs # PyO3 module definition
├── Cargo.toml # Rust dependencies
├── pyproject.toml # Python package configuration
├── build.py # Build script
├── example.py # Usage examples
└── README.md # This file
📚 API Reference
parse_formula(formula: str) -> dict
Parse a Wilkinson's formula string and return structured JSON metadata.
Parameters:
formula(str): The formula string to parse
Returns:
dict: Structured metadata describing the formula
Raises:
ValueError: If the formula is invalid or parsing fails
lex_formula(formula: str) -> dict
Tokenize a formula string and return JSON describing each token.
Parameters:
formula(str): The formula string to tokenize
Returns:
dict: Token information for each element in the formula
Raises:
ValueError: If the formula is invalid or lexing fails
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
📄 License
This project is licensed under the MIT License - see the fiasto repository for details.
🙏 Acknowledgments
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 Distributions
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 fiasto_py-0.1.0-cp313-cp313-macosx_11_0_arm64.whl.
File metadata
- Download URL: fiasto_py-0.1.0-cp313-cp313-macosx_11_0_arm64.whl
- Upload date:
- Size: 282.5 kB
- Tags: CPython 3.13, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2737542d0fb736a7f73d98ace34de8174112ee5f560d9eac4ecf275cc2bb467d
|
|
| MD5 |
d504cf6d8e8324ca902db5a83528b3cc
|
|
| BLAKE2b-256 |
a4de818bb9b078b2dd3b3fd23e37bbb7a5ef7ae30a2f4fab74d1da066c40bf3f
|