Skip to main content

Chilean RUT validation library with Pydantic, Django, and SQLAlchemy support

Project description

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
  • 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 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.number}")          # 20884437
print(f"Dígito: {rut.digit}")          # "7"
print(f"Formato: {rut.format}")        # RutFormat.DOTTED

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)  # "12.345.678-5"

Con Django

from django.db import models
from rut_validator.core.orm.django.schema 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.core.orm.sqlalchemy.schema import RutSQLAlchemy

Base = declarative_base()

class Person(Base):
    __tablename__ = 'persons'

    id = Column(Integer, primary_key=True)
    name = Column(String)
    rut = Column(RutSQLAlchemy)  # Validación automática

📚 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

Project details


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.1.0.tar.gz (13.1 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.1.0-py3-none-any.whl (16.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for rut_validator-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2ca3136fc17b536138fbb37c5259a9e9d335895009c9ad3412a6d7346a1f1eaa
MD5 cb64d70ea5af15537539256a13ea2b08
BLAKE2b-256 5ea0e18cd6a0d1b7117ad1341ae4cd169de65950908fc1457feb5c26aeff7de7

See more details on using hashes here.

Provenance

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

File metadata

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

File hashes

Hashes for rut_validator-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 95f0ac736a18c2b3bb897edfcb51c1d6c17316b109c8704ace1e8f9a84f516c6
MD5 1a68f28c4d62156b68200b5a3484dc1d
BLAKE2b-256 8f4950946151b843d70b5a6ecf90cfc5ca87cfde5aee553e237731d49106cb49

See more details on using hashes here.

Provenance

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

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page