Today I released the first stable release of
netsgiro to
PyPI. netsgiro is a Python 3.4+ library
for parsing and building Nets “OCR” files.

AvtaleGiro is a direct debit solution that is in widespread use in Norway, with
more than 15 000 companies offering it to their customers. OCR Giro is used by
Nets and Norwegian banks to update payees on recent deposits to their bank
accounts. In combination, AvtaleGiro and OCR Giro allows for a high level of
automation of invoicing and payment processing.

The “OCR” file format and file format name originates in days when giro
payments were delivered on paper to your bank and then processed either
manually or using optical character recognition, OCR. I’m not sure how old the
format is, but some of the examples in the OCR Giro specification use dates in
1993, and the specification changelog starts in 1999 and ends in 2003. A couple
of decades later, the file format is still in daily use by Nets’ AvtaleGiro
and OCR Giro services. In other words, I have high hopes that this will be a
very stable open source project requiring minimal maintenance efforts.

netsgiro is obviously not a child of recent changes in my spare time interests,
but was conceived as a part of our ongoing efforts in automating all aspects of
invoicing and payment processing for Otovo’s
residential solar and electricity customers. As such, netsgiro is Otovo’s
first open source project. Hopefully, it will soon
get some company on our public GitHub profile.

As of netsgiro 1.0.0, sloccount(1) counts 1160 lines of code and 948 lines of
tests, providing 97% statement coverage. In other words, netsgiro is a small
library trying to do one thing well. Meanwhile, enough effort has been poured
into it that I’m happy I was immediately allowed to open source the library,
hopefully saving others and my future self from doing the same work again.

The library is cleanly split in two layers. The lower level is called the
“records API” and is imported from netsgiro.records. The records API parses
OCR files line by line and returns one record object for each line it has
parsed. This is done with good help from Python’s multiline regexps and
enum.IntEnum, and
Hynek Schlawack’s excellent attrs.
Conversely, you can also create a bunch of record objects and convert them to
an OCR file.

The higher level “objects API” is imported from netsgiro. It combines
multiple records into higher level objects. For example, an AvtaleGiro payment
request can consist of up to 86 records, which in the higher level API is
represented by a single PaymentRequest object.

Otovo has been using netsgiro in production for about a month now, and so far
so good. We’re surely not the only shop in Norway doing invoicing with Python,
so I hope netsgiro will be a useful building block for others as well. If
you’re interested in learning more, start with the quickstart
guide and then continue
with the API reference.