https://github.com/duketemon/pydantic-swift-code
SWIFT/BIC code type using pydantic package
https://github.com/duketemon/pydantic-swift-code
pydantic-models pydantic-v2 swift swift-codes
Last synced: 9 months ago
JSON representation
SWIFT/BIC code type using pydantic package
- Host: GitHub
- URL: https://github.com/duketemon/pydantic-swift-code
- Owner: duketemon
- License: apache-2.0
- Created: 2024-11-16T07:51:32.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-11-25T17:41:20.000Z (over 1 year ago)
- Last Synced: 2025-07-22T06:35:55.214Z (about 1 year ago)
- Topics: pydantic-models, pydantic-v2, swift, swift-codes
- Language: Python
- Homepage:
- Size: 33.2 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Overview
Micro-package that defines a SWIFT/BIC code type using the Pydantic package
## Installation
Install from PyPI
```commandline
pip install pydantic-swift-code
```
Install from GitHub
```commandline
pip install git@github.com:duketemon/pydantic-swift-code.git
```
## Usage
```python
from pydantic import BaseModel, field_validator
from pydantic_swift_code import SwiftCode
class BankAccount(BaseModel):
...
swift_code: SwiftCode
@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
```