High-performance Chilean RUT validation & formatting (Cython)
Project description
PyRut
PyRut is a high-performance Python module leveraging Cython to accelerate computational tasks while maintaining the simplicity of Python. PyRut provides functions designed to handle Chilean RUT numbers (Rol Único Tributario) including validation, formatting, and computing verification digits.
Installation
Install PyRut directly from PyPI:
pip install PyRut
For development purposes or to build from source, clone the repository and run:
python setup.py build_ext --inplace
Usage
Below are examples demonstrating the functions provided by the 'rut' module.
Validating a RUT
from pyrut import validate_rut
# Validate RUT using the Cython implementation
if validate_rut("210496157"):
print("Valid RUT")
else:
print("Invalid RUT")
Using Suspicious RUT
from pyrut import validate_rut
# Validate RUT using the Cython implementation
if validate_rut("210496157", suspicious=true):
print("Valid RUT")
else:
print("Invalid RUT")
Formatting a RUT
from pyrut import format_rut
# Format the RUT string (e.g., "21049615-7" to "21.049.615-7")
formatted_rut = format_rut("21049615-7", dots=True)
print("Formatted RUT:", formatted_rut)
Computing the Verification Digit
from pyrut import verification_digit
# Calculate the verification digit for a given RUT number
digit = verification_digit("21049615")
print("Verification Digit:", digit)
Using list of RUTs
from pyrut import validate_list_ruts
# Validate a list of RUTs using the Cython implementation
ruts = ["11111111-1"] * 10000
valid_ruts = validate_list_ruts(ruts, suspicious=True)
print("Valid RUTs:", valid_ruts)
Using Type
from fastapi import FastAPI
from pyrut.types import Rut
app = FastAPI()
@app.get("/person/{rut}")
async def root(rut: Rut):
return {"message": "Hello World", "rut": rut}
@app.get("/person/{not-suspicious-rut}")
async def root(rut: RutNotSuspicious):
return {"message": "Hello World", "rut": rut}
Documentation
Detailed module documentation is available in the docs directory. See docs/index.md for complete details.
Running Tests
Unit tests are located in the tests directory. Run them using a testing framework like pytest:
pytest pyrut/tests
Contributing
Contributions are welcome! Please submit issues and pull requests for improvements.
License
This project is licensed under the MIT License. See the LICENSE file for details.
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
File details
Details for the file pyrut-1.2.0.tar.gz.
File metadata
- Download URL: pyrut-1.2.0.tar.gz
- Upload date:
- Size: 76.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6d71152c11fdf4f4735bd40819e91f451f152e25fc3d9dc15d83e4e760d6abdf
|
|
| MD5 |
0b5478e0727bac904b10b51865818b87
|
|
| BLAKE2b-256 |
a049605fe32563059619c45a010fd7df147e15420ba5e81a0d767f3b8eba9666
|
Provenance
The following attestation bundles were made for pyrut-1.2.0.tar.gz:
Publisher:
python-publish.yml on cve-zh00/PyRut
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyrut-1.2.0.tar.gz -
Subject digest:
6d71152c11fdf4f4735bd40819e91f451f152e25fc3d9dc15d83e4e760d6abdf - Sigstore transparency entry: 232055866
- Sigstore integration time:
-
Permalink:
cve-zh00/PyRut@51fc9d7da4941cc20a82a6ca0f68cdc789c154d0 -
Branch / Tag:
refs/tags/v1.2.0 - Owner: https://github.com/cve-zh00
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@51fc9d7da4941cc20a82a6ca0f68cdc789c154d0 -
Trigger Event:
release
-
Statement type: