All Projects → runfalk → Spans

runfalk / Spans

Licence: mit
Spans is a pure Python implementation of PostgreSQL's range types.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Spans

Period
PHP's time range API
Stars: ✭ 616 (+481.13%)
Mutual labels:  interval, range
Fastrange
A fast alternative to the modulo reduction
Stars: ✭ 230 (+116.98%)
Mutual labels:  interval, range
Angular Datetime Range
📅 Angular directive for datetime range input
Stars: ✭ 27 (-74.53%)
Mutual labels:  range
Functionalplus
Functional Programming Library for C++. Write concise and readable C++ code.
Stars: ✭ 1,286 (+1113.21%)
Mutual labels:  range
Buckets Js
A complete, fully tested and documented data structure library written in pure JavaScript.
Stars: ✭ 1,128 (+964.15%)
Mutual labels:  set
Fieldtop
Finds near-overflow columns in MySQL databases
Stars: ✭ 36 (-66.04%)
Mutual labels:  range
Git Repo Watcher
A simple bash script to watch a git repository and pull upstream changes if needed.
Stars: ✭ 73 (-31.13%)
Mutual labels:  interval
Time
Type-safe time calculations in Kotlin, powered by generics.
Stars: ✭ 939 (+785.85%)
Mutual labels:  interval
To Regex Range
Pass two numbers, get a regex-compatible source string for matching ranges. Fast compiler, optimized regex, and validated against more than 2.78 million test assertions. Useful for creating regular expressions to validate numbers, ranges, years, etc.
Stars: ✭ 97 (-8.49%)
Mutual labels:  range
Interval Arithmetic
An implementation of an algebraically closed interval system of the extended real number set
Stars: ✭ 60 (-43.4%)
Mutual labels:  interval
Dspn
[NeurIPS 2019] Deep Set Prediction Networks
Stars: ✭ 80 (-24.53%)
Mutual labels:  set
Persianrangedatepicker
Persian range date picker for android.
Stars: ✭ 48 (-54.72%)
Mutual labels:  range
Fill Range
Fill in a range of numbers or letters, positive or negative, optionally passing an increment or multiplier to use.
Stars: ✭ 41 (-61.32%)
Mutual labels:  range
Steamcmd Autoupdate Any Gameserver
Windows SteamCMD to autoupdate and install any game server steam cmd settings configurable lots of useful features. This batch script will keep your game servers automaticly updated updating intervals announce the server is shutting down for updates etc all configurable.
Stars: ✭ 77 (-27.36%)
Mutual labels:  interval
Quadtree Js
A simple quadtree implementation for javascript and typescript (nodejs or browser).
Stars: ✭ 36 (-66.04%)
Mutual labels:  range
Monster
The Art of Template MetaProgramming (TMP) in Modern C++♦️
Stars: ✭ 90 (-15.09%)
Mutual labels:  range
L
Simple set notation in Kotlin
Stars: ✭ 11 (-89.62%)
Mutual labels:  set
Apiset
API Set resolver for Windows
Stars: ✭ 42 (-60.38%)
Mutual labels:  set
Iso8601
Ruby parser to work with ISO8601 dateTimes and durations — http://en.wikipedia.org/wiki/ISO_8601
Stars: ✭ 70 (-33.96%)
Mutual labels:  interval
Moment Timer
Timer plugin for Moment.js that allows creation of setInterval and setTimeout-like timers.
Stars: ✭ 98 (-7.55%)
Mutual labels:  interval

Spans

|test-status| |test-coverage| |documentation-status| |pypi-version| |py-versions| |license|

Spans is a pure Python implementation of PostgreSQL's range types <http://www.postgresql.org/docs/9.6/static/rangetypes.html>_. Range types are convenient when working with intervals of any kind. Every time you've found yourself working with date_start and date_end, an interval may have been what you were actually looking for.

Spans has successfully been used in production since its first release 30th August, 2013.

Installation

Spans exists on PyPI.

.. code-block:: bash

$ pip install Spans

Documentation <http://spans.readthedocs.org/en/latest/>_ is hosted on Read the Docs.

Example

Imagine you are building a calendar and want to display all weeks that overlaps the current month. Normally you have to do some date trickery to achieve this, since the month's bounds may be any day of the week. With Spans' set-like operations and shortcuts the problem becomes a breeze.

We start by importing date and daterange

.. code-block:: python

>>> from datetime import date
>>> from spans import daterange

Using daterange.from_month we can get range representing January in the year 2000

.. code-block:: python

>>> month = daterange.from_month(2000, 1)
>>> month
daterange(datetime.date(2000, 1, 1), datetime.date(2000, 2, 1))

Now we can calculate the ranges for the weeks where the first and last day of month are

.. code-block:: python

>>> start_week = daterange.from_date(month.lower, period="week")
>>> end_week = daterange.from_date(month.last, period="week")
>>> start_week
daterange(datetime.date(1999, 12, 27), datetime.date(2000, 1, 3))
>>> end_week
daterange(datetime.date(2000, 1, 31), datetime.date(2000, 2, 7))

Using a union we can express the calendar view.

.. code-block:: python

>>> start_week.union(month).union(end_week)
daterange(datetime.date(1999, 12, 27), datetime.date(2000, 2, 7))

Do you want to know more? Head over to the documentation <http://spans.readthedocs.org/en/latest/>_.

Use with Psycopg2

To use these range types with Psycopg2 the PsycoSpans <https://www.github.com/runfalk/psycospans>_.

Motivation

For a project of mine I started using PostgreSQL's tsrange type and needed an equivalent in Python. These range types attempt to mimick PostgreSQL's behavior in every way. Deviating from it is considered as a bug and should be reported.

Contribute

I appreciate all the help I can get! Some things to think about:

  • If it's a simple fix, such as documentation or trivial bug fix, please file an issue or submit a pull request. Make sure to only touch lines relevant to the issue. I don't accept pull requests that simply reformat the code to be PEP8-compliant. To me the history of the repository is more important.
  • If it's a feature request or a non-trivial bug, always open an issue first to discuss the matter. It would be a shame if good work went to waste because a pull request doesn't fit the scope of this project.

Pull requests are credited in the change log which is displayed on PyPI and the documentaion on Read the Docs.

.. |test-status| image:: https://travis-ci.org/runfalk/spans.svg :alt: Test status :scale: 100% :target: https://travis-ci.org/runfalk/spans

.. |test-coverage| image:: https://codecov.io/github/runfalk/spans/coverage.svg?branch=master :alt: Test coverage :scale: 100% :target: https://codecov.io/github/runfalk/spans?branch=master

.. |documentation-status| image:: https://readthedocs.org/projects/spans/badge/ :alt: Documentation status :scale: 100% :target: http://spans.readthedocs.org/en/latest/

.. |pypi-version| image:: https://badge.fury.io/py/Spans.svg :alt: PyPI version status :scale: 100% :target: https://pypi.python.org/pypi/Spans/

.. |py-versions| image:: https://img.shields.io/pypi/pyversions/Spans.svg :alt: Python version :scale: 100% :target: https://pypi.python.org/pypi/Spans/

.. |license| image:: https://img.shields.io/github/license/runfalk/spans.svg :alt: MIT License :scale: 100% :target: https://github.com/runfalk/spans/blob/master/LICENSE

.. Include changelog on PyPI

.. include:: doc/changelog.rst

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].