Utilidades de RUT chilenos: validación, formateo, generación
Project description
Rutify
Librería Python para trabajar con RUT chilenos. Permite validar, formatear y generar RUTs de forma simple y eficiente.
Instalación
pip install rutify
Características
- Validación de RUTs completa
- Formateo en múltiples estilos
- Generación de RUTs aleatorios
- Sin dependencias externas
- Completamente tipado
- Soporte para Python 3.10+
Uso
Validación
from rutify import is_valid, is_valid_number
# Validar RUT completo
is_valid("12.345.678-5") # True
is_valid("12345678-5") # True
is_valid("12.345.678-0") # False
# Validar solo el número
is_valid_number(12345678) # True
is_valid_number(999) # False
# Validar múltiples RUTs
from rutify import validate_many
validate_many(["12.345.678-5", "98.765.432-1"])
# [True, True]
Formateo
from rutify import format_rut, normalize, mask, Rut, RutStyle
# Diferentes estilos de formato
rut = Rut.parse("12345678-5")
rut.format(RutStyle.DOTS) # "12.345.678-5"
rut.format(RutStyle.HYPHEN) # "12345678-5"
rut.format(RutStyle.PLAIN) # "123456785"
# Normalizar a formato estándar
normalize("123456785") # "12.345.678-5"
# Enmascarar RUT (ocultar dígitos)
mask("12.345.678-5") # "XX.XXX.678-5"
Generación
from rutify import generate, generate_many
# Generar un RUT aleatorio
rut = generate()
print(rut) # 15.234.567-8
# Generar múltiples RUTs
ruts = generate_many(5, unique=True)
# Generación segura (criptográficamente)
rut = generate(secure=True)
Clase Rut
from rutify import Rut
# Crear desde string
rut = Rut.parse("12.345.678-5")
# Crear desde número (calcula el DV automáticamente)
rut = Rut.from_number(12345678)
# Acceder a componentes
print(rut.number) # 12345678
print(rut.dv) # "5"
# Formatear
print(rut.format(RutStyle.DOTS)) # "12.345.678-5"
# Modo estricto (valida formato exacto)
Rut.parse("12.345.678-5", strict=True) # OK
Rut.parse("12345678-5", strict=True) # InvalidRutError
API
Validación
is_valid(rut: str) -> bool: Valida un RUT completois_valid_number(number: int) -> bool: Valida solo el número del RUTvalidate_many(ruts: list[str]) -> list[bool]: Valida múltiples RUTs
Formateo
format_rut(rut: str, style: RutStyle) -> str: Formatea según estilonormalize(rut: str) -> str: Normaliza a formato estándar con puntosmask(rut: str) -> str: Enmascara el RUT
Generación
generate(*, secure: bool = False) -> Rut: Genera un RUT aleatoriogenerate_many(count: int, *, unique: bool = True, secure: bool = False) -> list[Rut]: Genera múltiples RUTs
Clase Rut
Rut.parse(rut: str, *, strict: bool = False) -> Rut: Parsea desde stringRut.from_number(number: int) -> Rut: Crea desde númerorut.number: Obtiene el númerorut.dv: Obtiene el dígito verificadorrut.format(style: RutStyle) -> str: Formatea el RUT
Estilos disponibles
RutStyle.DOTS: Con puntos y guión (12.345.678-5)RutStyle.HYPHEN: Sin puntos, con guión (12345678-5)RutStyle.PLAIN: Sin formato (123456785)
Excepciones
RutifyError: Excepción baseInvalidRutError: RUT inválidoInvalidRutNumberError: Número de RUT inválido
Rangos válidos
Los RUTs válidos deben tener un número entre 1.000.000 y 99.999.999.
Licencia
MIT
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 Distribution
rutify-0.1.0.tar.gz
(13.6 kB
view details)
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 rutify-0.1.0.tar.gz.
File metadata
- Download URL: rutify-0.1.0.tar.gz
- Upload date:
- Size: 13.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
79a82e7eb4def106ec9fcd98744b872d1a83ca8c110f0dde143e6eb3f5cea82f
|
|
| MD5 |
4a5756dca3cc29fef0898dd95e562c62
|
|
| BLAKE2b-256 |
0d6892c61061ce7bf0278f45b0dd41e834e59668f35bdef53621a64be44b2b2c
|
File details
Details for the file rutify-0.1.0-py3-none-any.whl.
File metadata
- Download URL: rutify-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ccdfb68508cd745a50043cc58308362d9d2662c61664c81c8c726932bde5a8e4
|
|
| MD5 |
b737c150478063077c6ad1d61326b9ae
|
|
| BLAKE2b-256 |
e2083c06ee0b6637d4ad88327393a23b77705d35b40e9ded7499ec5c23c87af1
|