Skip to main content

pydantic SWIFT/BIC 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.2.0.tar.gz (5.9 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.2.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pydantic_swift_code-0.2.0.tar.gz
Algorithm Hash digest
SHA256 d49e308d38491338ce5218b7dab32cb48abb4fd20daad7fabf52404430759c54
MD5 3da60f4e2a998d9fd633a8e07c61aecf
BLAKE2b-256 bdd875f8e7114074a728a139a462b19b8f2f7b213a8d308005245b5b5e7bf7f4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pydantic_swift_code-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3677123e59e7938b0a582fc33027f41324406be4f34b1a0c65ee4ff30a33c9e2
MD5 a40bb4e8a2e82edb40f7afe6cdb33ab7
BLAKE2b-256 2d784530c36f4abb2fb6b95de836a02efe1f10a19c8b0ac2ec2498c389f323b6

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