{"id":4246,"library":"schwifty","title":"Schwifty IBAN and BIC Validation","description":"Schwifty is a Python library for easily working with IBANs and BICs as specified by the ISO, enabling validation, parsing, and generation of international bank account numbers and business identifier codes. It is actively maintained with regular monthly or bi-monthly releases, and the current version is 2026.3.0.","status":"active","version":"2026.3.0","language":"en","source_language":"en","source_url":"http://github.com/mdomke/schwifty","tags":["iban","bic","validation","banking","finance","pydantic"],"install":[{"cmd":"pip install schwifty","lang":"bash","label":"Standard Installation"},{"cmd":"pip install \"schwifty[pydantic]\"","lang":"bash","label":"With Pydantic integration"}],"dependencies":[{"reason":"Requires Python 3.10 or newer for current versions.","package":"python","optional":false},{"reason":"Used for accessing package data, conditionally for Python <= 3.11.","package":"importlib-resources","optional":false},{"reason":"Used for country-specific data.","package":"pycountry","optional":false},{"reason":"Used for generating random strings for IBAN/BIC generation.","package":"rstr","optional":false},{"reason":"Backports of typing features, conditionally for Python <= 3.10.","package":"typing-extensions","optional":false},{"reason":"Enables direct usage of IBAN and BIC types with Pydantic models for data validation. Requires `pydantic >= 2.0`.","package":"pydantic","optional":true}],"imports":[{"symbol":"IBAN","correct":"from schwifty import IBAN"},{"symbol":"BIC","correct":"from schwifty import BIC"}],"quickstart":{"code":"from schwifty import IBAN, BIC\n\n# Validate and parse an IBAN\ntry:\n    iban = IBAN('DE89 3704 0044 0532 0130 00')\n    print(f\"IBAN: {iban.formatted}\")\n    print(f\"Country Code: {iban.country_code}\")\n    print(f\"Bank Code: {iban.bank_code}\")\n    print(f\"Account Code: {iban.account_code}\")\n    print(f\"BIC (if available): {iban.bic}\")\nexcept ValueError as e:\n    print(f\"Invalid IBAN: {e}\")\n\n# Generate an IBAN\ngenerated_iban = IBAN.generate('GB', bank_code='040004', account_code='34340004')\nprint(f\"Generated IBAN: {generated_iban.formatted}\")\n\n# Create and validate a BIC\ntry:\n    bic = BIC('COBADEFFXXX')\n    print(f\"BIC: {bic.formatted}\")\n    print(f\"Country Code: {bic.country_code}\")\nexcept ValueError as e:\n    print(f\"Invalid BIC: {e}\")\n","lang":"python","description":"This quickstart demonstrates how to initialize `IBAN` and `BIC` objects, access their components, and generate new IBANs. Validation happens automatically upon instantiation, raising a `ValueError` (or a more specific `SchwiftyException` subclass) for invalid inputs."},"warnings":[{"fix":"Upgrade your Python environment to version 3.10 or a newer compatible version.","message":"Schwifty has periodically removed support for older Python versions. Python 3.9 was dropped in v2026.01.0, and Python 3.8 in v2024.11.0. The library currently requires Python 3.10 or newer.","severity":"breaking","affected_versions":"All versions since 2024.11.0"},{"fix":"For Pydantic models, use `iban: Annotated[IBAN, Field(strict=False)]` to allow lax validation.","message":"When integrating Schwifty's IBAN/BIC types with Pydantic, strict validation is enabled by default. To allow more lax validation (e.g., ignoring whitespace or formatting differences), the field must be explicitly annotated with `Field(strict=False)`.","severity":"gotcha","affected_versions":"2025.07.0 and later"},{"fix":"Update exception handling to catch `SchwiftyException` or its more specific subclasses (e.g., `InvalidCountryCode`, `InvalidChecksum`) for `schwifty`-related validation errors.","message":"The base exception class for all validation failures changed from `ValueError` to `SchwiftyException` (which subclasses `ValueError`) in version 2021.01.0. While catching `ValueError` will still work, direct catches of `ValueError` might be too broad. `SchwiftyException` offers more specific error subclasses for granular handling.","severity":"breaking","affected_versions":"2021.01.0 and later"},{"fix":"Ensure you are using `schwifty` version 2025.09.0 or newer when generating Polish IBANs. For older versions, meticulously validate any generated Polish IBANs.","message":"Prior to version 2025.09.0, the Polish IBAN format override could lead to unusual bank code breakdowns when generating IBANs from individual components. This could result in incorrectly structured IBANs if not thoroughly validated.","severity":"gotcha","affected_versions":"Versions prior to 2025.09.0"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}