Skip to main content

rut-validator

PyPI version Python versions License: MIT CI codecov Documentation Status

Librería para validar RUT chileno con enfoque Pydantic-first y soporte completo para frameworks web.

✨ Características

  • Validación pura de RUT chileno usando algoritmo módulo 11
  • Detección automática de formato: dotted (12.345.678-9), hyphenated (12345678-9), numeric (123456789)
  • Integración completa con Pydantic (RutStr)
  • Campo Django (RUTField) listo para usar
  • Tipo SQLAlchemy (RutSQLAlchemy) para bases de datos
  • Integración SQLModel con almacenamiento normalizado
  • Compatible con FastAPI y otros frameworks web
  • Type hints completos para mejor desarrollo
  • Sin dependencias externas para funcionalidad core
  • Tests exhaustivos con alta cobertura

🚀 Instalación

pip install rut-validator

# Con soporte Pydantic
pip install rut-validator[pydantic]

# Con soporte para una integración concreta
pip install rut-validator[sqlalchemy]
pip install rut-validator[django]
pip install rut-validator[sqlmodel]

# Con soporte FastAPI
pip install rut-validator[fastapi]

# Todas las integraciones
pip install rut-validator[all]

# Para desarrollo
pip install rut-validator[dev]

📖 Uso Básico

Validación Simple

from rut_validator import RutValidator

# Validar RUT con cualquier formato
rut = RutValidator.validate("20.884.437-7")
print(f"RUT válido: {rut.formatted}")  # "20.884.437-7"
print(f"Número: {rut.body}")           # 20884437
print(f"Dígito: {rut.check_digit}")    # "7"
print(f"Formato: {rut.format}")        # RutFormat.FORMATTED

Para un uso funcional más directo:

from rut_validator import calculate_check_digit, validate_rut

rut = validate_rut("12.345.678-5")
assert rut.normalized == "123456785"
assert calculate_check_digit("12345678") == "5"

Detección de Formato

from rut_validator import RutValidator

# La librería detecta automáticamente el formato de entrada
formats = [
    "20.884.437-7",  # Formato dotted
    "20884437-7",    # Formato hyphenated
    "208844377",     # Formato numeric
]

for rut_str in formats:
    rut = RutValidator.validate(rut_str)
    print(f"'{rut_str}' -> Formato: {rut.format}, Es dotted: {rut.is_dotted}")

Con Pydantic

from pydantic import BaseModel
from rut_validator import RutStr

class User(BaseModel):
    name: str
    rut: RutStr  # Validación automática

# Uso
user = User(name="Juan Pérez", rut="12.345.678-5")
print(user.rut)  # "123456785" (normalizado)

Con Django

from django.db import models
from rut_validator.orm.django import RUTField

class Person(models.Model):
    name = models.CharField(max_length=100)
    rut = RUTField(unique=True)  # Validación automática en DB

Con SQLAlchemy

from sqlalchemy import Column, Integer, String
from sqlalchemy.ext.declarative import declarative_base
from rut_validator.orm.sqlalchemy import RutType

Base = declarative_base()

class Person(Base):
    __tablename__ = 'persons'

    id = Column(Integer, primary_key=True)
    name = Column(String)
    rut = Column(RutType)  # Validación y normalización automáticas

📚 Guía Completa

Lee la documentación completa en docs/GUIA_RUT_VALIDATOR.md

🧪 Ejemplos

🔧 Desarrollo

Configuración del entorno

# Clonar repositorio
git clone https://github.com/ezer-mackenzie/rut-validator.git
cd rut-validator

# Instalar dependencias de desarrollo
poetry install --with dev

# Ejecutar tests
poetry run pytest

# Ejecutar linting
poetry run black src/ tests/
poetry run isort src/ tests/
poetry run flake8 src/ tests/
poetry run mypy src/rut_validator/

Pre-commit hooks

poetry run pre-commit install

🤝 Contribuir

  1. Fork el proyecto
  2. Crea una rama para tu feature (git checkout -b feature/AmazingFeature)
  3. Commit tus cambios (git commit -m 'Add some AmazingFeature')
  4. Push a la rama (git push origin feature/AmazingFeature)
  5. Abre un Pull Request

📄 Licencia

Este proyecto está bajo la Licencia MIT - ver el archivo LICENSE para más detalles.

🙏 Agradecimientos

  • Algoritmo de validación basado en el estándar chileno del Servicio de Impuestos Internos
  • Inspirado en bibliotecas similares pero con enfoque moderno y tipado fuerte

📞 Soporte

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rut_validator-0.3.0.tar.gz (15.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rut_validator-0.3.0-py3-none-any.whl (20.9 kB view details)

Uploaded Python 3

File details

Details for the file rut_validator-0.3.0.tar.gz.

File metadata

  • Download URL: rut_validator-0.3.0.tar.gz
  • Upload date:
  • Size: 15.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for rut_validator-0.3.0.tar.gz
Algorithm Hash digest
SHA256 9f4db2b2642226e72e262d723038d18bb16266b6a711a011fb338e6cd9a51935
MD5 16f753b26881bd1cd717e0cee3d6fa54
BLAKE2b-256 2c943ed70b42e311c6cd1233c1b007ebc1119d59ffb7eb67ef73d1cd3161a982

See more details on using hashes here.

Provenance

The following attestation bundles were made for rut_validator-0.3.0.tar.gz:

Publisher: publish.yml on ezer-mackenzie/rut-validator

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rut_validator-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: rut_validator-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 20.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for rut_validator-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fe8251bac0bf3396c8fe384ff3870560d1b0224107b70e78e7c59d7ba12878d1
MD5 39486f4c838b84a4aa6cbbbf047148cd
BLAKE2b-256 df7daf1056ea0998517353f02e08d411dce3dce1d17321880032d4108806f16f

See more details on using hashes here.

Provenance

The following attestation bundles were made for rut_validator-0.3.0-py3-none-any.whl:

Publisher: publish.yml on ezer-mackenzie/rut-validator

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

2.0.0

2 files

1.1.0

2 files

1.0.1

2 files

1.0.0

2 files

0.9.0

2 files

0.8.0

2 files

0.7.0

2 files

0.6.0

2 files

0.5.0

2 files

0.4.0

2 files

This release

0.3.0 This release

2 files

0.2.0

2 files

0.1.0

2 files

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