arthurdejong / python-stdnum

A Python library to provide functions to handle, parse and validate standard numbers.
https://arthurdejong.org/python-stdnum/
GNU Lesser General Public License v2.1
495 stars 205 forks source link

Add ISRC (International Standard Recording Code) #261

Closed nuno-andre closed 3 years ago

nuno-andre commented 3 years ago

Hi!

This PR adds support for the ISRC (International Standard Recording Code).

I've also added a little function to util.py that I often use to split strings into different sizes. I think it could be useful for other codes. If you think that it's misplaced or misnamed I have no problem in modifying the commit.

>>> chunks = 3, 4, 5, 4
>>> segment('0123456789ABCDEF', *chunks)
['012', '3456', '789AB', 'CDEF']

Also, comment that I'm writing a wrapper to use python-stdnum with Pydantic (Pydentic). I have a little library with some validators for Pydantic models, and I've found that yours has almost all of them (and many more), so I think it's way more productive to add the missing ones to python-stdnum and wrap it up. Currently, it is little more than a proof of concept but I will develop it in the next few days, and will also send some more PRs if you like.

Thanks for your work, it's really amazing. I wish I had known about it sooner :)

arthurdejong commented 3 years ago

Hi @nuno-andre,

Thanks for providing the number format. I've merged it as 36d723c. I took out the segment() function for now because it was slightly easier to switch to a regex than to turn it into something that also works for Python 2.7 (only recently support for Python 2.6 was dropped).

If there are any formats missing I would welcome pull requests but creating issues with a request for the format is also fine.

In general, python-stdnum is meant to be used in situations like with Pydantic (didn't know about that library before). I recommend calling compact() on a number before storing it in a database or similar storage because it tries to ensure a consistent for for the number so that it is easier to do queries for the number.

Thanks!