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]

# 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

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/yourusername/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.2.0.tar.gz (14.4 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.2.0-py3-none-any.whl (19.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: rut_validator-0.2.0.tar.gz
  • Upload date:
  • Size: 14.4 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.2.0.tar.gz
Algorithm Hash digest
SHA256 5c3589c946a07955853857208368ab80c9811545a66599b7db1b3e155be9158b
MD5 2140c22334e69b3f1ba282cf83f7c96d
BLAKE2b-256 736aa2da34a62e22c68156cb2d2a8b1b7c10f6aaca9657ac15473c08cc4c6f32

See more details on using hashes here.

Provenance

The following attestation bundles were made for rut_validator-0.2.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.2.0-py3-none-any.whl.

File metadata

  • Download URL: rut_validator-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 19.3 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c8c0b06621b8a215bac8fdf90235361721da001e1cc48cfead68428aa4a4730a
MD5 0fd84c113e787fff64e8f0d755f80921
BLAKE2b-256 000672295bf6d7f0cbcb77e8d882de2b779d44d88bb6aa08c9242d2b2c75070e

See more details on using hashes here.

Provenance

The following attestation bundles were made for rut_validator-0.2.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

0.3.0

2 files

This release

0.2.0 This release

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