Skip to main content

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.

Metadata

Release files for PyRut 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for PyRut 1.2.0
File Size Uploaded Provenance Actions
pyrut-1.2.0.tar.gz 76.4 kB With provenance Details for pyrut-1.2.0.tar.gz

Release files / pyrut-1.2.0.tar.gz

Download URL pyrut-1.2.0.tar.gz
Size 76.4 kB
Tags Source
SHA-256 checksum
How to use checksums
6d71152c11fdf4f4735bd40819e91f451f152e25fc3d9dc15d83e4e760d6abdf
BLAKE2b-256 checksum
How to use checksums
a049605fe32563059619c45a010fd7df147e15420ba5e81a0d767f3b8eba9666
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 7, 2025.

Transparency log

Security for PyRut 1.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

1 file in this release has been uploaded with provenance metadata.

Attestation for pyrut-1.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 7, 2025.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page