Rut.py is a Python library for handling Chilean RUTs (Rol Único Tributario). It provides functions to clean, validate, get the check digit, format, and generate RUTs.
This library is based on the JavaScript library rut.js by jlobos. It aims to bring similar functionality to Python developers working with Chilean RUTs.
You can install Rut.py using pip:
pip install rutpyTo use RutPy, first import the necessary functions:
from rutpy import clean, validate, get_check_digit, format, generateYou can then use the functions according to your needs.
The clean function is used to remove dots and hyphens from a RUT:
rut = "14.961.581-4"
clean_rut = clean(rut)
print(clean_rut) # Output: 149615814The validate function is used to check whether a RUT is valid or not:
rut = "14.961.581-4"
is_valid = validate(rut)
print(is_valid) # Output: TrueThe get_check_digit function is used to retrieve the check digit of a RUT:
rut = "14.961.581"
check_digit = get_check_digit(rut)
print(check_digit) # Output: 4The format function is used to format a RUT with dots and hyphen:
rut = "14961581"
formatted_rut = format(rut)
print(formatted_rut) # Output: 14.961.581The generate function is used to generate a valid RUT:
rut = generate()
print(rut) # Output: A randomly generated valid RUTContributions are welcome. If you find any issues, have any improvement ideas, or want to add new features, you can open an issue or submit a pull request on the GitHub repository.
Rut.py is distributed under the MIT License.