Andreas Runfalk

Spans

Spans is a pure Python implementation of PostgreSQL's range types. Range types are conveinent when working with intervals of any kind. Every time you've found yourself working with date_start and date_end, an interval like Spans' range may have been what you were actually looking for.

I originally made Spans back in 2013 as part of my company's workshift management application Permutar. After realizing its usefulness I refactored it into a library and put it on PyPI. I don't have any user statistics, but before download statistics were disabled in June 2016 it had been downloaded at least 18,000 times.

>>> from spans import daterange
>>> daterange.from_month(2000, 1)
daterange([datetime.date(2000, 1, 1),datetime.date(2000, 2, 1)))

Psycospans

Psycospans integrates Spans with the database driver Psycopg2. Since the primary purpose of Spans was to re-implement PostgreSQL's range types this works very well out of the box.

The main purpose of this library was to use range types with Canonical's Storm ORM. This project is used by StormSpans.

>>> from psycospans import connect
>>> from spans import intrange
>>> conn = connect("dbname=test")
>>> cur = conn.cursor()
>>> test_range = intrange(1, 10)
>>> cur.execute("SELECT int4range(5, NULL), %s", (test_range,))
>>> a, b = cur.fetchone()
>>> a
intrange([5,))
>>> b
intrange([1,10))

Stormspans

Stormspans brings support for PostgreSQL's range types to Canonical's Storm ORM using Psycospans paired with Spans.