PyRyu is a Rust-powered Python library that provides efficient conversion of floating point numbers to their shortest string representation using the Ryu algorithm. This project demonstrates how to build Python bindings using PyO3.
- Fast conversion of floating point numbers to strings.
- Simple Python interface to a Rust library.
- Handles edge cases like NaN and infinity.
Before you begin, ensure you have met the following requirements:
- Rust Toolchain (latest stable recommended)
- Python 3.7 or higher
- Poetry for Python dependency management
Follow these steps to install PyRyu:
-
Clone the repository:
git clone https://github.com/mrcsparker/pyryu.git cd pyryu
-
Build the project:
poetry install poetry run maturin build poetry run pytest
This command builds the Rust code and installs the Python package into a virtual environment managed by Poetry.
Here is a simple example of how to use PyRyu in a Python script:
from pyryu import PyRyu
ryu = PyRyu()
number = 3.14159
print("Formatted number:", ryu.format(number))
This script creates an instance of PyRyu
and formats a floating point number.
To set up a development environment for this project:
-
Install dependencies:
poetry install
-
To build and test locally:
poetry run pytest
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
To contribute to PyRyu, follow these steps:
- Fork the repository.
- Create your feature branch (
git checkout -b feature/AmazingFeature
). - Commit your changes (
git commit -m 'Add some AmazingFeature'
). - Push to the branch (
git push origin feature/AmazingFeature
). - Open a pull request.
Distributed under the MIT License. See LICENSE
for more information.
Project Link: https://github.com/mrcsparker/pyryu