### Install schwifty Source: https://schwifty.readthedocs.io/en/latest/index.html Install the schwifty Python library using pip. Requires Python 3.6+. ```bash $ pip install schwifty ``` -------------------------------- ### IBAN Validate BBAN Checksum Example (Constructor) Source: https://schwifty.readthedocs.io/en/latest/examples.html Shows how to opt-in to BBAN checksum validation using the `IBAN` constructor parameter. ```python >>> IBAN('DE20 2909 0900 8840 0170 00', validate_bban=True) ... InvalidBBANChecksum: Invalid BBAN checksum ``` -------------------------------- ### IBAN Validate BBAN Checksum Example (Method) Source: https://schwifty.readthedocs.io/en/latest/examples.html Shows how to opt-in to BBAN checksum validation using the `validate` method. ```python >>> iban = IBAN('DE20 2909 0900 8840 0170 00') >>> iban.validate(validate_bban=True) ... InvalidBBANChecksum: Invalid BBAN checksum ``` -------------------------------- ### Get Formatted BIC Source: https://schwifty.readthedocs.io/en/latest/api.html Get the BIC string formatted with spaces separating the bank, country, and location codes. ```python >>> BIC("MARKDEF1100").formatted 'MARK DE F1 100' ``` -------------------------------- ### BIC Invalid Structure Example Source: https://schwifty.readthedocs.io/en/latest/examples.html Demonstrates a BIC validation error for an invalid structure. ```python >>> BIC('PBNKD1FFXXXX') ... InvalidStructure: Invalid structure PBN1DXFFXXXX ``` -------------------------------- ### IBAN Invalid Country Code Example Source: https://schwifty.readthedocs.io/en/latest/examples.html Demonstrates an IBAN validation error for an unknown country code. ```python >>> IBAN('DX89 3704 0044 0532 0130 00') ... InvalidCountryCode: Unknown country-code DX ``` -------------------------------- ### BIC Strict SWIFT Compliance Example Source: https://schwifty.readthedocs.io/en/latest/examples.html Shows how to enforce strict SWIFT compliance for BIC validation, disallowing numbers in the business prefix. ```python >>> BIC("1234DEWWXXX", enforce_swift_compliance=True) ... InvalidStructure: Invalid structure 1234DEWWXXX ``` -------------------------------- ### IBAN Invalid Checksum Digits Example Source: https://schwifty.readthedocs.io/en/latest/examples.html Demonstrates an IBAN validation error due to incorrect checksum digits. ```python >>> IBAN('DE99 3704 0044 0532 0130 00') ... InvalidChecksumDigits: Invalid checksum digits ``` -------------------------------- ### BIC Invalid Length Example Source: https://schwifty.readthedocs.io/en/latest/examples.html Demonstrates a BIC validation error for an incorrect length. ```python >>> BIC('PBNKDXFFXXXX') ... InvalidLength: Invalid length 12 ``` -------------------------------- ### Get Bank Information for Random IBAN Source: https://schwifty.readthedocs.io/en/latest/examples.html Generates a random IBAN for a specified country and retrieves its associated bank information from the registry. ```python >>> IBAN.random(country_code="DE").bank {'bank_code': '42870077', 'name': 'Deutsche Bank', 'short_name': 'Deutsche Bank', 'bic': 'DEUTDE3B428', 'primary': True, 'country_code': 'DE', 'checksum_algo': '63'} ``` -------------------------------- ### Get IBAN Account Type Source: https://schwifty.readthedocs.io/en/latest/_modules/schwifty/iban.html Property that returns the account type specifier. This is only available for IBANs from Seychelles, Brazil, and Bulgaria. ```python @property def account_type(self) -> str: """str: Account type specifier. This value is only available for Seychelles, Brazil and Bulgaria. """ return self.bban.account_type ``` -------------------------------- ### Get IBAN Currency Code Source: https://schwifty.readthedocs.io/en/latest/_modules/schwifty/iban.html Property that returns the currency code of the account. This is only available for IBANs from Mauretania, Seychelles, and Guatemala. ```python @property def currency_code(self) -> str: """str: The account's currency code. This value is only available for Mauretania, Seychelles and Guatemala. """ return self.bban.currency_code ``` -------------------------------- ### Get Domestic Bank Codes from BIC Source: https://schwifty.readthedocs.io/en/latest/_sources/examples.rst.txt Lists the country-specific bank codes associated with a BIC. ```pycon >>> bic.domestic_bank_codes ['10010010', '20010020', ... '86010090'] ``` -------------------------------- ### BIC Invalid Country Code Example Source: https://schwifty.readthedocs.io/en/latest/examples.html Demonstrates a BIC validation error for an invalid country code. ```python >>> BIC('PBNKDXFFXXX') ... InvalidCountryCode: Invalid country code DX ``` -------------------------------- ### Get IBAN Account Code Source: https://schwifty.readthedocs.io/en/latest/_modules/schwifty/iban.html Property that returns the domestic account code, which is part of the BBAN. ```python @property def account_code(self) -> str: """str: The domestic account-code""" return self.bban.account_code ``` -------------------------------- ### Get IBAN Bank Code Source: https://schwifty.readthedocs.io/en/latest/_modules/schwifty/iban.html Property that returns the country-specific bank code, which is a component of the BBAN. ```python @property def bank_code(self) -> str: """str: The country specific bank-code.""" return self.bban.bank_code ``` -------------------------------- ### IBAN is_valid Property Example Source: https://schwifty.readthedocs.io/en/latest/examples.html Illustrates using the `is_valid` property for a non-exceptional IBAN validation check. Note that this does not validate national checksum digits. ```python if IBAN(value, allow_invalid=True).is_valid: # do something with value ``` -------------------------------- ### Get IBAN Bank Information Source: https://schwifty.readthedocs.io/en/latest/_modules/schwifty/iban.html Property that returns a dictionary containing information about the bank associated with the IBAN's bank code, as part of the BBAN. Returns None if no information is available. ```python @property def bank(self) -> dict | None: """dict or None: The information of the bank related to the bank code as part of the BBAN""" return self.bban.bank ``` -------------------------------- ### Get IBAN Branch Code Source: https://schwifty.readthedocs.io/en/latest/_modules/schwifty/iban.html Property that returns the branch code of the bank, if available as part of the BBAN. ```python @property def branch_code(self) -> str: """str: The branch-code of the bank if available.""" return self.bban.branch_code ``` -------------------------------- ### Get IBAN Account ID Source: https://schwifty.readthedocs.io/en/latest/_modules/schwifty/iban.html Property that returns the holder-specific account identification. Currently, this is only available for IBANs from Brazil. ```python @property def account_id(self) -> str: """str: Holder specific account identification. This is currently only available for Brazil. """ return self.bban.account_id ``` -------------------------------- ### Get IBAN Country Specification Source: https://schwifty.readthedocs.io/en/latest/_modules/schwifty/iban.html Property that retrieves the country-specific IBAN specification from the registry. Raises an InvalidCountryCode exception if the country code is unknown. ```python @property def spec(self) -> dict[str, Any]: """dict: The country specific IBAN specification.""" try: spec = registry.get("iban") assert isinstance(spec, dict) return spec[self.country_code] except KeyError as e: raise exceptions.InvalidCountryCode( f"Unknown country-code '{self.country_code}'" ) from e ``` -------------------------------- ### Get BIC candidates from bank code Source: https://schwifty.readthedocs.io/en/latest/_sources/examples.rst.txt Retrieve a list of all known BIC candidates associated with a given domestic bank code and country. This is useful when multiple BICs might correspond to a single bank code. ```pycon >>> BIC.candidates_from_bank_code('FR', '30004') # doctest: +NORMALIZE_WHITESPACE [, , , , , , , , , , , , , , , , , , , , , , ] ``` -------------------------------- ### Get IBAN Bank Short Name Source: https://schwifty.readthedocs.io/en/latest/_modules/schwifty/iban.html Property that retrieves a shortened name of the bank associated with the IBAN's bank code. Returns None if the short name is not available. ```python @property def bank_short_name(self) -> str | None: """str or None: The name of the bank associated with the IBAN bank code. Examples: >>> IBAN("DE89370400440532013000").bank_short_name 'Commerzbank Köln' ``` -------------------------------- ### Get IBAN Country Information Source: https://schwifty.readthedocs.io/en/latest/_modules/schwifty/iban.html Property that retrieves the country object associated with the IBAN's country code. Returns None if the country code is not found. ```python @property def country(self) -> Data | None: """Country: The country this IBAN is registered in.""" return countries.get(alpha_2=self.country_code) ``` -------------------------------- ### Get IBAN Bank Name Source: https://schwifty.readthedocs.io/en/latest/_modules/schwifty/iban.html Property that retrieves the full name of the bank associated with the IBAN's bank code. Returns None if the bank name is not available. ```python @property def bank_name(self) -> str | None: """str or None: The name of the bank associated with the IBAN bank code. Examples: >>> IBAN("DE89370400440532013000").bank_name 'Commerzbank' .. versionadded:: 2022.04.2 """ return self.bban.bank_name ``` -------------------------------- ### Instantiate BBAN from Components Source: https://schwifty.readthedocs.io/en/latest/api.html Demonstrates how to create a BBAN object by providing the country code and specific components like the account code and bank code. ```python >>> BBAN.from_components("DE", account_code="0532013000", bank_code="37040044") ``` -------------------------------- ### Get Bank Names of a BIC Source: https://schwifty.readthedocs.io/en/latest/api.html Retrieve a list of bank names associated with a BIC. This is the recommended way to get bank names since version 2020.01.0. ```python >>> BIC("MARKDEF1100").bank_names ['Bundesbank'] ``` -------------------------------- ### Get Domestic Bank Codes of a BIC Source: https://schwifty.readthedocs.io/en/latest/api.html Retrieve a list of country-specific bank codes associated with a BIC. This is the recommended way to get domestic bank codes since version 2020.01.0. ```python >>> BIC("MARKDEF1100").domestic_bank_codes ['10000000'] ``` -------------------------------- ### Create BIC Object Source: https://schwifty.readthedocs.io/en/latest/_sources/examples.rst.txt Demonstrates how to create a BIC object from its string representation. ```pycon >>> from schwifty import BIC >>> bic = BIC('PBNKDEFFXXX') >>> bic.bank_code 'PBNK' >>> bic.branch_code 'XXX' >>> bic.country_code 'DE' >>> bic.location_code 'FF' ``` -------------------------------- ### Get Bank Short Names of a BIC Source: https://schwifty.readthedocs.io/en/latest/api.html Retrieve a list of short bank names associated with a BIC. This is the recommended way to get bank short names since version 2020.01.0. ```python >>> BIC("MARKDEF1100").bank_short_names ['BBk Berlin'] ``` -------------------------------- ### Generate IBAN with Country-Specific Components Source: https://schwifty.readthedocs.io/en/latest/changelog.html Demonstrates how to generate an IBAN by providing country-specific components like bank code, account type, account code, and account holder ID. ```python >>> IBAN.generate("IS", bank_code="0101", account_type="26", account_code="85002", account_holder_id="5402696029") ``` -------------------------------- ### Get BIC Location Code Source: https://schwifty.readthedocs.io/en/latest/_modules/schwifty/bic.html Extracts the location code from a BIC. ```python from schwifty import BIC print(BIC("MARKDEF1100").location_code) # Expected output: '1100' ``` -------------------------------- ### Create and Access IBAN Components Source: https://schwifty.readthedocs.io/en/latest/api.html Instantiate an IBAN object with a given code and access its various components as properties. The IBAN is validated upon creation. ```python >>> iban = IBAN('DE89 3704 0044 0532 0130 00') >>> iban.account_code '0532013000' >>> iban.bank_code '37040044' >>> iban.country_code 'DE' >>> iban.checksum_digits '89' >>> iban.bban ``` -------------------------------- ### Get BIC Bank Code Source: https://schwifty.readthedocs.io/en/latest/_modules/schwifty/bic.html Extracts the bank code part from a BIC. ```python from schwifty import BIC print(BIC("MARKDEF1100").bank_code) # Expected output: 'MARK' ``` -------------------------------- ### Get Bank Name from BBAN Source: https://schwifty.readthedocs.io/en/latest/api.html Retrieves the name of the bank associated with a BBAN object. ```python >>> BBAN("DE", "370400440532013000").bank_name 'Commerzbank' ``` -------------------------------- ### Instantiate and Access IBAN Components Source: https://schwifty.readthedocs.io/en/latest/_modules/schwifty/iban.html Create an IBAN object from a string and access its components like account code, bank code, country code, checksum digits, and the BBAN object. Validation is performed on instantiation unless `allow_invalid` is True. ```python from schwifty import IBAN try: iban = IBAN('DE89 3704 0044 0532 0130 00') print(f'Account Code: {iban.account_code}') print(f'Bank Code: {iban.bank_code}') print(f'Country Code: {iban.country_code}') print(f'Checksum Digits: {iban.checksum_digits}') print(f'BBAN: {iban.bban}') except exceptions.InvalidStructure as e: print(f'Invalid structure: {e}') except exceptions.InvalidChecksumDigits as e: print(f'Invalid checksum: {e}') except exceptions.InvalidLength as e: print(f'Invalid length: {e}') ``` -------------------------------- ### BIC Class Initialization Source: https://schwifty.readthedocs.io/en/latest/api.html Instantiate a BIC object with a given code. Validation is performed by default, but can be bypassed or made stricter using parameters. ```APIDOC ## BIC Class Initialization ### Description Instantiate a BIC object with a given code. Validation is performed by default, but can be bypassed or made stricter using parameters. ### Parameters * **_value** (_str_) – The BIC value. * **allow_invalid** (_bool_) – If set to `True` validation is skipped on instantiation. * **enforce_swift_compliance** (_bool_) – If set to `True` the stricter SWIFT BIC policy is applied. ### Raises * **InvalidLength** – If the BIC’s length is not 8 or 11 characters long. * **InvalidStructure** – If the BIC contains unexpected characters. * **InvalidCountryCode** – If the BIC’s country code is unknown. ### Examples ```python >>> bic = BIC('GENODEM1GLS') >>> bic.country_code 'DE' >>> bic.location_code 'M1' >>> bic.bank_code 'GENO' ``` ``` -------------------------------- ### Get BIC Branch Code Source: https://schwifty.readthedocs.io/en/latest/_modules/schwifty/bic.html Extracts the branch code part from a BIC, if available. ```python from schwifty import BIC print(BIC("MARKDEF1100").branch_code) # Expected output: '1100' ``` -------------------------------- ### Generate IBAN with Checksum Source: https://schwifty.readthedocs.io/en/latest/examples.html Generates an IBAN from country code, bank code, and account number. The checksum digits are automatically calculated. ```python >>> iban = IBAN.generate('DE', bank_code='10010010', account_code='12345') >>> iban.checksum_digits '40' ``` -------------------------------- ### Create IBAN object from string Source: https://schwifty.readthedocs.io/en/latest/examples.html Instantiate an IBAN object from its string representation. This is the primary way to create IBAN objects. ```python >>> from schwifty import IBAN >>> iban = IBAN('DE89 3704 0044 0532 0130 00') ``` -------------------------------- ### PyInstaller Data Collection Source: https://schwifty.readthedocs.io/en/latest/changelog.html Use this command when packaging the library with PyInstaller to ensure data files are collected and metadata is copied. ```bash $ pyinstaller