Skip to main content

pydantic SWIFT code type

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pydantic_swift_code-0.1.0.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pydantic_swift_code-0.1.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file pydantic_swift_code-0.1.0.tar.gz.

File metadata

  • Download URL: pydantic_swift_code-0.1.0.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.13.0 Darwin/23.6.0

File hashes

Hashes for pydantic_swift_code-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7bf1e0671f0690ae21e008c086cf0e9baecf81177d5251a6d57465a0719cb3ac
MD5 24c38a8e7b9a9dfc24b687e5319d2820
BLAKE2b-256 c22f6e03597e6d6ac4e7d1012e6a2013586a10c8ba8cdd9b26c624c42bacfcd3

See more details on using hashes here.

File details

Details for the file pydantic_swift_code-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pydantic_swift_code-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7ef0264aa42d8664f42980358710ab67b39c67af6c86ee5eaac23e00072f0102
MD5 e6e3e59e97aa4f51ff106b66656f99ac
BLAKE2b-256 7520c9644c317fc44eca72e5085acd44794a6197533dac0e31bf209ab583bd0f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page