dud-cl-rut
Lean Chilean RUT validation and formatting for Python.
Same behavior as the TypeScript package, with snake_case names.
Install
pip install dud-cl-rut
Usage
from dud_cl import rut
value = rut.parse("18.972.631-7")
# "189726317"
rut.format(value) # "18.972.631-7"
rut.format(value, dots=False) # "18972631-7"
k_value = rut.parse("9.068.826-k")
rut.format(k_value, uppercase=False) # "9.068.826-k"
rut.safe_parse("18.972.631-0")
# SafeParseFailure(success=False, issue=CheckDigitIssue(...))
rut.is_rut("9068826k") # True (TS export is `is`)
rut.clean("0018.972.631-7") # "189726317"
rut.get_verifier("9.068.826") # "K"
rut.compare("18.972.631-7", "189726317") # True
With Pydantic
parse raises RutError, a ValueError subclass, so it can be used directly with AfterValidator:
from typing import Annotated
from pydantic import AfterValidator, BaseModel
from dud_cl.rut import parse
class User(BaseModel):
national_id: Annotated[str, AfterValidator(parse)]
user = User(national_id="18.972.631-7")
user.national_id # "189726317"
API
| Function | Role |
|---|---|
parse(input) |
Validate; return cleaned RUT or raise RutError |
safe_parse(input) |
Validate; return success/failure result |
is_rut(input) |
Return whether input is valid (is in TypeScript) |
format(rut, *, dots=True, uppercase=True) |
Format a validated Rut |
clean(input) |
Normalize without validating |
compare(left, right) |
Compare canonical values; both inputs must be valid |
get_verifier(body) |
Calculate a valid body verifier; return None if invalid |
parse / safe_parse / is_rut require a canonical length of 8-9 (7-8 digit body + DV). parse and successful safe_parse results are the supported way to create values accepted by format.
Develop
uv sync --extra dev
uv run pytest
uv run mypy
License
MIT
Release files for dud-cl-rut 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| dud_cl_rut-0.1.0.tar.gz | 4.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| dud_cl_rut-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.1 kB
Release files / dud_cl_rut-0.1.0.tar.gz
| Download URL | dud_cl_rut-0.1.0.tar.gz |
|---|---|
| Size | 4.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8d48bb011b36bb5aea90e49b7fc938ab89ce0089173e9fb7f0590876d27c48d2
|
|
BLAKE2b-256 checksum How to use checksums |
6b555b67fad29545082d2db72429252e36b7c4ef081f20d94a86db8a2d713e28
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / dud_cl_rut-0.1.0-py3-none-any.whl
| Download URL | dud_cl_rut-0.1.0-py3-none-any.whl |
|---|---|
| Size | 6.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9b854586753c3733f2315d15ab5ee86b1e3800a9abb988202a2ca48b7909ac02
|
|
BLAKE2b-256 checksum How to use checksums |
92103778b10cfe01ff7809f7c3c71efcf87930d02ccf8230e3fd2040e475ad21
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|