Chilean RUT validation library with Pydantic, Django, and SQLAlchemy support
Project description
rut-validator
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
- Fork el proyecto
- Crea una rama para tu feature (
git checkout -b feature/AmazingFeature) - Commit tus cambios (
git commit -m 'Add some AmazingFeature') - Push a la rama (
git push origin feature/AmazingFeature) - 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
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
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ca3136fc17b536138fbb37c5259a9e9d335895009c9ad3412a6d7346a1f1eaa
|
|
| MD5 |
cb64d70ea5af15537539256a13ea2b08
|
|
| BLAKE2b-256 |
5ea0e18cd6a0d1b7117ad1341ae4cd169de65950908fc1457feb5c26aeff7de7
|
Provenance
The following attestation bundles were made for rut_validator-0.1.0.tar.gz:
Publisher:
publish.yml on ezer-mackenzie/rut-validator
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rut_validator-0.1.0.tar.gz -
Subject digest:
2ca3136fc17b536138fbb37c5259a9e9d335895009c9ad3412a6d7346a1f1eaa - Sigstore transparency entry: 1624716869
- Sigstore integration time:
-
Permalink:
ezer-mackenzie/rut-validator@f092ca24f915ff6c3d75abf7d31176c0e8be00f3 -
Branch / Tag:
refs/tags/0.1.0 - Owner: https://github.com/ezer-mackenzie
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f092ca24f915ff6c3d75abf7d31176c0e8be00f3 -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
95f0ac736a18c2b3bb897edfcb51c1d6c17316b109c8704ace1e8f9a84f516c6
|
|
| MD5 |
1a68f28c4d62156b68200b5a3484dc1d
|
|
| BLAKE2b-256 |
8f4950946151b843d70b5a6ecf90cfc5ca87cfde5aee553e237731d49106cb49
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rut_validator-0.1.0-py3-none-any.whl -
Subject digest:
95f0ac736a18c2b3bb897edfcb51c1d6c17316b109c8704ace1e8f9a84f516c6 - Sigstore transparency entry: 1624716875
- Sigstore integration time:
-
Permalink:
ezer-mackenzie/rut-validator@f092ca24f915ff6c3d75abf7d31176c0e8be00f3 -
Branch / Tag:
refs/tags/0.1.0 - Owner: https://github.com/ezer-mackenzie
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f092ca24f915ff6c3d75abf7d31176c0e8be00f3 -
Trigger Event:
release
-
Statement type: