Overview
Micro-package that defines a SWIFT code type using the Pydantic package
Installation
Install from PyPI
pip install pydantic-swift-code
Install from GitHub
pip install git@github.com:duketemon/pydantic-swift-code.git
Usage
from typing import Optional
from pydantic import BaseModel, field_validator
from pydantic_swift_code import SwiftCode
class BankAccount(BaseModel):
swift_code: SwiftCode
@field_validator("swift_code", mode="before")
@classmethod
def validate_swift_code_before_init(cls, swift_code: Optional[str]) -> str:
"""Make input case-insensitive"""
if swift_code is None:
raise ValueError("Received None value, expected string")
return swift_code.upper()
@field_validator("swift_code", mode="after")
@classmethod
def validate_swift_code_after_init(cls, swift_code: str) -> str:
"""Custom validation"""
if swift_code[:4] not in {"REVO", "MONZ"}:
raise ValueError("Only Revolut and Monzo swift codes are allowed")
if swift_code[4:6] not in {"US", "GB"}:
raise ValueError("Only GB and US swift codes are allowed")
return swift_code
Release files for pydantic-swift-code 0.2.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 | |
|---|---|---|---|
| pydantic_swift_code-0.2.0.tar.gz | 5.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pydantic_swift_code-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 12.4 kB
Release files / pydantic_swift_code-0.2.0.tar.gz
| Download URL | pydantic_swift_code-0.2.0.tar.gz |
|---|---|
| Size | 5.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d49e308d38491338ce5218b7dab32cb48abb4fd20daad7fabf52404430759c54
|
|
BLAKE2b-256 checksum How to use checksums |
bdd875f8e7114074a728a139a462b19b8f2f7b213a8d308005245b5b5e7bf7f4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.4 CPython/3.13.0 Darwin/24.1.0
|
Release files / pydantic_swift_code-0.2.0-py3-none-any.whl
| Download URL | pydantic_swift_code-0.2.0-py3-none-any.whl |
|---|---|
| Size | 6.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3677123e59e7938b0a582fc33027f41324406be4f34b1a0c65ee4ff30a33c9e2
|
|
BLAKE2b-256 checksum How to use checksums |
2d784530c36f4abb2fb6b95de836a02efe1f10a19c8b0ac2ec2498c389f323b6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.4 CPython/3.13.0 Darwin/24.1.0
|