{"id":13936537,"url":"https://github.com/runfalk/spans","last_synced_at":"2025-07-29T02:34:13.120Z","repository":{"id":10348357,"uuid":"12484739","full_name":"runfalk/spans","owner":"runfalk","description":"Spans is a pure Python implementation of PostgreSQL's range types.","archived":false,"fork":false,"pushed_at":"2022-12-09T06:52:51.000Z","size":552,"stargazers_count":112,"open_issues_count":4,"forks_count":11,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-07-01T06:48:51.325Z","etag":null,"topics":["datatype","interval","python-2","python-3","range","set"],"latest_commit_sha":null,"homepage":"https://runfalk.github.io/spans/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/runfalk.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-08-30T11:16:12.000Z","updated_at":"2024-01-13T23:51:43.000Z","dependencies_parsed_at":"2023-01-13T15:53:16.474Z","dependency_job_id":null,"html_url":"https://github.com/runfalk/spans","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/runfalk/spans","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/runfalk%2Fspans","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/runfalk%2Fspans/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/runfalk%2Fspans/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/runfalk%2Fspans/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/runfalk","download_url":"https://codeload.github.com/runfalk/spans/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/runfalk%2Fspans/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267619051,"owners_count":24116486,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-29T02:00:12.549Z","response_time":2574,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["datatype","interval","python-2","python-3","range","set"],"created_at":"2024-08-07T23:02:45.791Z","updated_at":"2025-07-29T02:34:13.098Z","avatar_url":"https://github.com/runfalk.png","language":"Python","readme":"Spans\n=====\n|pypi-version| |py-versions| |license|\n\nSpans is a pure Python implementation of PostgreSQL's\n`range types \u003chttp://www.postgresql.org/docs/9.6/static/rangetypes.html\u003e`_.\nRange types are convenient when working with intervals of any kind. Every time\nyou've found yourself working with date_start and date_end, an interval may have\nbeen what you were actually looking for.\n\nSpans has successfully been used in production since its first release\n30th August, 2013.\n\n\nInstallation\n------------\nSpans exists on PyPI.\n\n.. code-block:: bash\n\n    $ pip install Spans\n\n`Documentation \u003chttp://spans.readthedocs.org/en/latest/\u003e`_ is hosted on Read the\nDocs.\n\n\nExample\n-------\nImagine you are building a calendar and want to display all weeks that overlaps\nthe current month. Normally you have to do some date trickery to achieve this,\nsince the month's bounds may be any day of the week. With Spans' set-like\noperations and shortcuts the problem becomes a breeze.\n\nWe start by importing ``date`` and ``daterange``\n\n.. code-block:: python\n\n    \u003e\u003e\u003e from datetime import date\n    \u003e\u003e\u003e from spans import daterange\n\nUsing ``daterange.from_month`` we can get range representing January in the year\n2000\n\n.. code-block:: python\n\n    \u003e\u003e\u003e month = daterange.from_month(2000, 1)\n    \u003e\u003e\u003e month\n    daterange(datetime.date(2000, 1, 1), datetime.date(2000, 2, 1))\n\nNow we can calculate the ranges for the weeks where the first and last day of\nmonth are\n\n.. code-block:: python\n\n    \u003e\u003e\u003e start_week = daterange.from_date(month.lower, period=\"week\")\n    \u003e\u003e\u003e end_week = daterange.from_date(month.last, period=\"week\")\n    \u003e\u003e\u003e start_week\n    daterange(datetime.date(1999, 12, 27), datetime.date(2000, 1, 3))\n    \u003e\u003e\u003e end_week\n    daterange(datetime.date(2000, 1, 31), datetime.date(2000, 2, 7))\n\nUsing a union we can express the calendar view.\n\n.. code-block:: python\n\n    \u003e\u003e\u003e start_week.union(month).union(end_week)\n    daterange(datetime.date(1999, 12, 27), datetime.date(2000, 2, 7))\n\nDo you want to know more? Head over to the\n`documentation \u003chttp://spans.readthedocs.org/en/latest/\u003e`_.\n\n\nUse with Psycopg2\n-----------------\nTo use these range types with Psycopg2 the\n`PsycoSpans \u003chttps://www.github.com/runfalk/psycospans\u003e`_.\n\n\nMotivation\n----------\nFor a project of mine I started using PostgreSQL's ``tsrange`` type and needed\nan equivalent in Python. These range types attempt to mimick PostgreSQL's\nbehavior in every way. Deviating from it is considered as a bug and should be\nreported.\n\n\nContribute\n----------\nI appreciate all the help I can get! Some things to think about:\n\n- If it's a simple fix, such as documentation or trivial bug fix, please file\n  an issue or submit a pull request. Make sure to only touch lines relevant to\n  the issue. I don't accept pull requests that simply reformat the code to be\n  PEP8-compliant. To me the history of the repository is more important.\n- If it's a feature request or a non-trivial bug, always open an issue first to\n  discuss the matter. It would be a shame if good work went to waste because a\n  pull request doesn't fit the scope of this project.\n\nPull requests are credited in the change log which is displayed on PyPI and the\ndocumentaion on Read the Docs.\n\n\n.. |pypi-version| image:: https://badge.fury.io/py/Spans.svg\n    :alt: PyPI version status\n    :scale: 100%\n    :target: https://pypi.python.org/pypi/Spans/\n\n.. |py-versions| image:: https://img.shields.io/pypi/pyversions/Spans.svg\n    :alt: Python version\n    :scale: 100%\n    :target: https://pypi.python.org/pypi/Spans/\n\n.. |license| image:: https://img.shields.io/github/license/runfalk/spans.svg\n    :alt: MIT License\n    :scale: 100%\n    :target: https://github.com/runfalk/spans/blob/master/LICENSE\n\n.. Include changelog on PyPI\n\n.. include:: doc/changelog.rst\n","funding_links":[],"categories":["Python"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frunfalk%2Fspans","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frunfalk%2Fspans","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frunfalk%2Fspans/lists"}