validate
pinky_core.validate
Input validation and standardization helpers.
No top-level external imports — each function lazy-loads its dependency so the module is importable without any optional package installed.
Optional dependencies (install the ones you need)::
pip install pinky-core[validate] # all validators
pip install email-validator # standardize_email
pip install phonenumbers # standardize_phone
pip install python-stdnum # validate_siret, validate_nir
Each function returns a typed result model. Call .model_dump() to convert
to a plain dict when a Snowflake UDF handler needs to return a VARIANT/OBJECT.
EmailResult
Bases: BaseModel
Result of standardize_email.
Source code in src/pinky_core/validate.py
32 33 34 35 36 37 38 39 40 41 42 43 | |
FrIdResult
Bases: BaseModel
Result of validate_siret — SIRET, SIREN, or TVA intra-community.
Source code in src/pinky_core/validate.py
59 60 61 62 63 64 65 66 67 68 | |
IbanBicResult
Bases: BaseModel
Result of validate_iban_bic.
Source code in src/pinky_core/validate.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 | |
NirResult
Bases: BaseModel
Result of validate_nir.
Source code in src/pinky_core/validate.py
71 72 73 74 75 76 77 78 79 80 81 | |
PhoneResult
Bases: BaseModel
Result of standardize_phone for a single number.
Source code in src/pinky_core/validate.py
46 47 48 49 50 51 52 53 54 55 56 | |
VatResult
Bases: BaseModel
Result of validate_vat_eu.
Source code in src/pinky_core/validate.py
84 85 86 87 88 89 90 91 92 | |
standardize_email(email)
Validate and normalize an email address.
Uses email-validator to parse and normalize the address without
checking deliverability (no DNS lookup).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
email
|
str
|
Raw email string to validate. |
required |
Returns:
| Type | Description |
|---|---|
EmailResult
|
|
EmailResult
|
success, or |
Source code in src/pinky_core/validate.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | |
standardize_phone(phone_number, country_code=None, default_country='FR')
Validate and normalize a phone number.
Detects the country from international prefixes when possible, then
falls back to country_code, then to default_country.
Uses the phonenumbers library.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
phone_number
|
str
|
Raw phone string (any format). |
required |
country_code
|
str | None
|
ISO 3166-1 alpha-2 country from the source data.
Pass |
None
|
default_country
|
str
|
Last-resort fallback when neither an international
prefix nor |
'FR'
|
Returns:
| Type | Description |
|---|---|
PhoneResult | list[PhoneResult]
|
A |
PhoneResult | list[PhoneResult]
|
numbers are found in the string, or a |
PhoneResult | list[PhoneResult]
|
|
Source code in src/pinky_core/validate.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | |
validate_iban_bic(value)
Validate an IBAN or BIC/SWIFT code.
No external dependencies — uses pure-Python mod-97 checksum for IBAN.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
Raw IBAN or BIC string (spaces and dashes allowed, will be stripped). |
required |
Returns:
| Type | Description |
|---|---|
IbanBicResult
|
|
IbanBicResult
|
or |
Source code in src/pinky_core/validate.py
466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 | |
validate_nir(value)
Validate a French NIR (numéro de sécurité sociale).
Uses the python-stdnum library (stdnum.fr.nir).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
Raw NIR string (spaces allowed, will be stripped). |
required |
Returns:
| Type | Description |
|---|---|
NirResult
|
|
NirResult
|
or |
Source code in src/pinky_core/validate.py
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 | |
validate_siret(value)
Validate a French SIRET, SIREN, or TVA (intra-community) number.
Dispatches by length/prefix:
- 14 digits → SIRET
- 9 digits → SIREN
- FR + 11 chars → TVA intra-community
Uses the python-stdnum library (stdnum.fr).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
Raw identifier string (spaces allowed, will be stripped). |
required |
Returns:
| Type | Description |
|---|---|
FrIdResult
|
|
FrIdResult
|
or |
Source code in src/pinky_core/validate.py
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 | |
validate_vat_eu(value)
Validate a European VAT number.
Supports all EU member states via the python-stdnum library
(stdnum.eu.vat). The country prefix (first 2 chars) determines
the country-specific validation rules.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
Raw VAT string — spaces, dots and dashes are stripped before
validation (e.g. |
required |
Returns:
| Type | Description |
|---|---|
VatResult
|
|
VatResult
|
or |
Example::
validate_vat_eu("FR12345678901")
# VatResult(is_valid=True, country_code="FR", local_number="12345678901", …) # pragma: allowlist secret
Source code in src/pinky_core/validate.py
529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 | |