Skip to content

Commit

Permalink
Add changelog and examples for IBAN.random()
Browse files Browse the repository at this point in the history
  • Loading branch information
mdomke committed May 10, 2024
1 parent c4b30f6 commit 3c974a8
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
25 changes: 25 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,30 @@ Changelog

Versions follow `CalVer <http://www.calver.org/>`_ with the scheme ``YY.0M.Micro``.

`2024.05.3`_ - 2024/05/10
-------------------------
Added
~~~~~
* There is a new classmethod ``IBAN.random()`` that allows you to create random, but valid IBANs.

.. code-block:: pycon
>>> IBAN.random()
<IBAN=LT435012771675726758>
You can narrow down the generated values by providing the corresponding parameters to this
function. E.g. to get only Spanish IBANs you can do

.. code-block:: pycon
>>> IBAN.random(country_code="ES")
<IBAN=ES8801253179194914182449>
Changed
~~~~~~~
* Some missing bank associations have been added to the Portoguese bank registry by
`@tiagoafseixas <https://github.com/tiagoafseixas>`_

`2024.05.2`_ - 2024/05/09
-------------------------
Fixed
Expand Down Expand Up @@ -599,6 +623,7 @@ Added
* Added :attr:`.BIC.country` and :attr:`.IBAN.country`.


.. _2024.05.3: https://github.com/mdomke/schwifty/compare/2024.05.2...2024.05.3
.. _2024.05.2: https://github.com/mdomke/schwifty/compare/2024.05.1...2024.05.2
.. _2024.05.1: https://github.com/mdomke/schwifty/compare/2024.05.0...2024.05.1
.. _2024.05.0: https://github.com/mdomke/schwifty/compare/2024.04.0...2024.05.0
Expand Down
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Features
* `validate`_ format and country codes from BICs
* `generate`_ BICs from country and bank-code
* `generate`_ IBANs from country-code, bank-code and account-number.
* `generate`_ random valid IBANs
* get the BIC associated to an IBAN's bank-code
* access all relevant components as attributes

Expand Down
43 changes: 43 additions & 0 deletions docs/source/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,49 @@ In case there are multiple BICs that can be related to a domestic bank code you
<BIC=BNPAFRPPPEE>, <BIC=BNPAFRPPPXV>, <BIC=BNPAFRPPIFO>]
Random IBANs
~~~~~~~~~~~~

For testing and other usecases it might be useful to generate random IBANs. Therefore you can simply
call

.. code-block:: pycon
>>> IBAN.random()
<IBAN=IT53D0838265738IXCFNXEVWPNL>
and you will get a random but valid IBAN. You can also predefine some parameters of the random
result to narrow down the possible values, e.g.

.. code-block:: pycon
>>> IBAN.random(country_code="GB")
<IBAN=GB67COBA74887171221908>
will give you a British IBAN. Similarly,

.. code-block:: pycon
>>> IBAN.random(country_code="GB", bank_code="LOYD")
<IBAN=GB53LOYD00952296262556>
will only give you IBANs from the Lloyds Bank.

Notice that for countries that have a bank registry, the bank code will always be taken from there,
so that the IBAN corresponds to a valid bank. E.g.:

.. code-block:: pycon
>>> 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'}
Pydantic integration
---------------------

Expand Down

0 comments on commit 3c974a8

Please sign in to comment.