Python Sorted Containers

Python Sorted Containers - Published in JOSS (2019)

https://github.com/grantjenks/python-sortedcontainers

Science Score: 95.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 1 DOI reference(s) in JOSS metadata
  • Academic publication links
  • Committers with academic emails
    1 of 25 committers (4.0%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
    Published in Journal of Open Source Software

Keywords

data-types dict list python set sorted

Keywords from Contributors

fuzzing property-based-testing

Scientific Fields

Mathematics Computer Science - 84% confidence
Last synced: 4 months ago · JSON representation

Repository

Python Sorted Container Types: Sorted List, Sorted Dict, and Sorted Set

Basic Info
Statistics
  • Stars: 3,801
  • Watchers: 36
  • Forks: 218
  • Open Issues: 34
  • Releases: 1
Topics
data-types dict list python set sorted
Created almost 12 years ago · Last pushed almost 2 years ago
Metadata Files
Readme Changelog License

README.rst

Python Sorted Containers
========================

`Sorted Containers`_ is an Apache2 licensed `sorted collections library`_,
written in pure-Python, and fast as C-extensions.

Python's standard library is great until you need a sorted collections
type. Many will attest that you can get really far without one, but the moment
you **really need** a sorted list, sorted dict, or sorted set, you're faced
with a dozen different implementations, most using C-extensions without great
documentation and benchmarking.

In Python, we can do better. And we can do it in pure-Python!

.. code-block:: python

    >>> from sortedcontainers import SortedList
    >>> sl = SortedList(['e', 'a', 'c', 'd', 'b'])
    >>> sl
    SortedList(['a', 'b', 'c', 'd', 'e'])
    >>> sl *= 10_000_000
    >>> sl.count('c')
    10000000
    >>> sl[-3:]
    ['e', 'e', 'e']
    >>> from sortedcontainers import SortedDict
    >>> sd = SortedDict({'c': -3, 'a': 1, 'b': 2})
    >>> sd
    SortedDict({'a': 1, 'b': 2, 'c': -3})
    >>> sd.popitem(index=-1)
    ('c', -3)
    >>> from sortedcontainers import SortedSet
    >>> ss = SortedSet('abracadabra')
    >>> ss
    SortedSet(['a', 'b', 'c', 'd', 'r'])
    >>> ss.bisect_left('c')
    2

All of the operations shown above run in faster than linear time. The above
demo also takes nearly a gigabyte of memory to run. When the sorted list is
multiplied by ten million, it stores ten million references to each of "a"
through "e". Each reference requires eight bytes in the sorted
container. That's pretty hard to beat as it's the cost of a pointer to each
object. It's also 66% less overhead than a typical binary tree implementation
(e.g. Red-Black Tree, AVL-Tree, AA-Tree, Splay-Tree, Treap, etc.) for which
every node must also store two pointers to children nodes.

`Sorted Containers`_ takes all of the work out of Python sorted collections -
making your deployment and use of Python easy. There's no need to install a C
compiler or pre-build and distribute custom extensions. Performance is a
feature and testing has 100% coverage with unit tests and hours of stress.

.. _`Sorted Containers`: http://www.grantjenks.com/docs/sortedcontainers/
.. _`sorted collections library`: http://www.grantjenks.com/docs/sortedcontainers/

Testimonials
------------

**Alex Martelli**, `Fellow of the Python Software Foundation`_

"Good stuff! ... I like the `simple, effective implementation`_ idea of
splitting the sorted containers into smaller "fragments" to avoid the O(N)
insertion costs."

**Jeff Knupp**, `author of Writing Idiomatic Python and Python Trainer`_

"That last part, "fast as C-extensions," was difficult to believe. I would need
some sort of `Performance Comparison`_ to be convinced this is true. The author
includes this in the docs. It is."

**Kevin Samuel**, `Python and Django Trainer`_

I'm quite amazed, not just by the code quality (it's incredibly readable and
has more comment than code, wow), but the actual amount of work you put at
stuff that is *not* code: documentation, benchmarking, implementation
explanations. Even the git log is clean and the unit tests run out of the box
on Python 2 and 3.

**Mark Summerfield**, a short plea for `Python Sorted Collections`_

Python's "batteries included" standard library seems to have a battery
missing. And the argument that "we never had it before" has worn thin. It is
time that Python offered a full range of collection classes out of the box,
including sorted ones.

`Sorted Containers`_ is used in popular open source projects such as:
`Zipline`_, an algorithmic trading library from Quantopian; `Angr`_, a binary
analysis platform from UC Santa Barbara; `Trio`_, an async I/O library; and
`Dask Distributed`_, a distributed computation library supported by Continuum
Analytics.

.. _`Fellow of the Python Software Foundation`: https://en.wikipedia.org/wiki/Alex_Martelli
.. _`simple, effective implementation`: http://www.grantjenks.com/docs/sortedcontainers/implementation.html
.. _`author of Writing Idiomatic Python and Python Trainer`: https://jeffknupp.com/
.. _`Python and Django Trainer`: https://www.elephorm.com/formateur/kevin-samuel
.. _`Python Sorted Collections`: http://www.qtrac.eu/pysorted.html
.. _`Zipline`: https://github.com/quantopian/zipline
.. _`Angr`: https://github.com/angr/angr
.. _`Trio`: https://github.com/python-trio/trio
.. _`Dask Distributed`: https://github.com/dask/distributed

Features
--------

- Pure-Python
- Fully documented
- Benchmark comparison (alternatives, runtimes, load-factors)
- 100% test coverage
- Hours of stress testing
- Performance matters (often faster than C implementations)
- Compatible API (nearly identical to older blist and bintrees modules)
- Feature-rich (e.g. get the five largest keys in a sorted dict: d.keys()[-5:])
- Pragmatic design (e.g. SortedSet is a Python set with a SortedList index)
- Developed on Python 3.10
- Tested with CPython 3.7, 3.8, 3.9, 3.10, 3.11, 3.12 and PyPy3
- Tested on Linux, Mac OSX, and Windows

.. image:: https://github.com/grantjenks/python-sortedcontainers/workflows/integration/badge.svg
   :target: http://www.grantjenks.com/docs/sortedcontainers/

.. image:: https://github.com/grantjenks/python-sortedcontainers/workflows/release/badge.svg
   :target: http://www.grantjenks.com/docs/sortedcontainers/

Quickstart
----------

Installing `Sorted Containers`_ is simple with `pip
`_::

    $ pip install sortedcontainers

You can access documentation in the interpreter with Python's built-in `help`
function. The `help` works on modules, classes and methods in `Sorted
Containers`_.

.. code-block:: python

    >>> import sortedcontainers
    >>> help(sortedcontainers)
    >>> from sortedcontainers import SortedDict
    >>> help(SortedDict)
    >>> help(SortedDict.popitem)

Documentation
-------------

Complete documentation for `Sorted Containers`_ is available at
http://www.grantjenks.com/docs/sortedcontainers/

User Guide
..........

The user guide provides an introduction to `Sorted Containers`_ and extensive
performance comparisons and analysis.

- `Introduction`_
- `Performance Comparison`_
- `Load Factor Performance Comparison`_
- `Runtime Performance Comparison`_
- `Simulated Workload Performance Comparison`_
- `Performance at Scale`_

.. _`Introduction`: http://www.grantjenks.com/docs/sortedcontainers/introduction.html
.. _`Performance Comparison`: http://www.grantjenks.com/docs/sortedcontainers/performance.html
.. _`Load Factor Performance Comparison`: http://www.grantjenks.com/docs/sortedcontainers/performance-load.html
.. _`Runtime Performance Comparison`: http://www.grantjenks.com/docs/sortedcontainers/performance-runtime.html
.. _`Simulated Workload Performance Comparison`: http://www.grantjenks.com/docs/sortedcontainers/performance-workload.html
.. _`Performance at Scale`: http://www.grantjenks.com/docs/sortedcontainers/performance-scale.html

Community Guide
...............

The community guide provides information on the development of `Sorted
Containers`_ along with support, implementation, and history details.

- `Development and Support`_
- `Implementation Details`_
- `Release History`_

.. _`Development and Support`: http://www.grantjenks.com/docs/sortedcontainers/development.html
.. _`Implementation Details`: http://www.grantjenks.com/docs/sortedcontainers/implementation.html
.. _`Release History`: http://www.grantjenks.com/docs/sortedcontainers/history.html

API Documentation
.................

The API documentation provides information on specific functions, classes, and
modules in the `Sorted Containers`_ package.

- `Sorted List`_
- `Sorted Dict`_
- `Sorted Set`_

.. _`Sorted List`: http://www.grantjenks.com/docs/sortedcontainers/sortedlist.html
.. _`Sorted Dict`: http://www.grantjenks.com/docs/sortedcontainers/sorteddict.html
.. _`Sorted Set`: http://www.grantjenks.com/docs/sortedcontainers/sortedset.html

Talks
-----

- `Python Sorted Collections | PyCon 2016 Talk`_
- `SF Python Holiday Party 2015 Lightning Talk`_
- `DjangoCon 2015 Lightning Talk`_

.. _`Python Sorted Collections | PyCon 2016 Talk`: http://www.grantjenks.com/docs/sortedcontainers/pycon-2016-talk.html
.. _`SF Python Holiday Party 2015 Lightning Talk`: http://www.grantjenks.com/docs/sortedcontainers/sf-python-2015-lightning-talk.html
.. _`DjangoCon 2015 Lightning Talk`: http://www.grantjenks.com/docs/sortedcontainers/djangocon-2015-lightning-talk.html

Resources
---------

- `Sorted Containers Documentation`_
- `Sorted Containers at PyPI`_
- `Sorted Containers at Github`_
- `Sorted Containers Issue Tracker`_

.. _`Sorted Containers Documentation`: http://www.grantjenks.com/docs/sortedcontainers/
.. _`Sorted Containers at PyPI`: https://pypi.org/project/sortedcontainers/
.. _`Sorted Containers at Github`: https://github.com/grantjenks/python-sortedcontainers
.. _`Sorted Containers Issue Tracker`: https://github.com/grantjenks/python-sortedcontainers/issues

Sorted Containers License
-------------------------

Copyright 2014-2024 Grant Jenks

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Owner

  • Name: Grant Jenks
  • Login: grantjenks
  • Kind: user
  • Location: Bay Area, CA

listen | learn | think | solve

JOSS Publication

Python Sorted Containers
Published
June 03, 2019
Volume 4, Issue 38, Page 1330
Authors
Grant Jenks ORCID
None
Editor
Jason Clark ORCID
Tags
sorted list dictionary set

GitHub Events

Total
  • Issues event: 3
  • Watch event: 282
  • Issue comment event: 14
  • Pull request event: 1
  • Fork event: 15
Last Year
  • Issues event: 3
  • Watch event: 282
  • Issue comment event: 14
  • Pull request event: 1
  • Fork event: 15

Committers

Last synced: 5 months ago

All Time
  • Total Commits: 632
  • Total Committers: 25
  • Avg Commits per committer: 25.28
  • Development Distribution Score (DDS): 0.38
Past Year
  • Commits: 21
  • Committers: 2
  • Avg Commits per committer: 10.5
  • Development Distribution Score (DDS): 0.048
Top Committers
Name Email Commits
Grant Jenks c****t@g****m 392
Grant Jenks g****s@g****m 207
Omer Katz o****w@g****m 5
Pedro Rodrigues m****u@g****m 4
Tim Gates t****s@i****m 2
Jonathan Eunice j****e@g****m 2
John Belmonte j****n@n****t 2
eukaryote s****b@g****m 1
Adam Chainz me@a****u 1
Felix Yan f****s@a****g 1
Hugo van Kemenade 1****k 1
Jakob Keller 5****r 1
Jakub Wilk j****k@j****t 1
Yuki Asano 9****3 1
ismailmaj 7****j 1
tortarino 6****o 1
bamartin125 b****5@g****m 1
Wouter Bolsterlee u****s@x****l 1
Wilfred Hughes me@w****k 1
Anthony Sottile a****e@u****u 1
Felix Van der Jeugt f****t@g****m 1
Grant Jenks g****j@g****t 1
Mak Nazečić-Andrlon o****n@g****m 1
Maximilian Hils g****t@m****m 1
Nathaniel Brown n****n@g****m 1

Issues and Pull Requests

Last synced: 4 months ago

All Time
  • Total issues: 98
  • Total pull requests: 32
  • Average time to close issues: 6 months
  • Average time to close pull requests: about 1 year
  • Total issue authors: 93
  • Total pull request authors: 22
  • Average comments per issue: 2.53
  • Average comments per pull request: 2.97
  • Merged pull requests: 13
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 3
  • Pull requests: 3
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 3
  • Pull request authors: 2
  • Average comments per issue: 0.33
  • Average comments per pull request: 0.0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • grantjenks (3)
  • pganssle (2)
  • gboeer (2)
  • theoneisneo (2)
  • bastiat (2)
  • Sinha-Ujjawal (1)
  • jakob-keller (1)
  • whfuyn (1)
  • joelmiller (1)
  • Daenyth (1)
  • skettlitz (1)
  • pjz (1)
  • timborden (1)
  • pengdlzn (1)
  • anuraggupta29 (1)
Pull Request Authors
  • hugovk (4)
  • pganssle (3)
  • grantjenks (3)
  • althonos (2)
  • bsamedi (2)
  • jakob-keller (2)
  • Asayu123 (2)
  • belm0 (2)
  • Madoshakalaka (2)
  • RScrusoe (2)
  • h4l (1)
  • Greeshmanth1 (1)
  • ismailmaj (1)
  • cool-RR (1)
  • bamartin125 (1)
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 4
  • Total downloads:
    • pypi 131,556,604 last-month
  • Total docker downloads: 1,774,095,636
  • Total dependent packages: 468
    (may contain duplicates)
  • Total dependent repositories: 24,395
    (may contain duplicates)
  • Total versions: 105
  • Total maintainers: 1
pypi.org: sortedcontainers

Sorted Containers -- Sorted List, Sorted Dict, Sorted Set

  • Versions: 40
  • Dependent Packages: 414
  • Dependent Repositories: 23,703
  • Downloads: 131,556,604 Last month
  • Docker Downloads: 1,774,095,636
Rankings
Downloads: 0.0%
Docker downloads count: 0.0%
Dependent repos count: 0.1%
Average: 0.1%
Dependent packages count: 0.1%
Maintainers (1)
Last synced: 4 months ago
proxy.golang.org: github.com/grantjenks/python-sortedcontainers
  • Versions: 41
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Stargazers count: 1.2%
Forks count: 1.8%
Average: 5.9%
Dependent packages count: 9.6%
Dependent repos count: 10.8%
Last synced: 4 months ago
conda-forge.org: sortedcontainers

SortedContainers is a sorted collections library, written in pure-Python and fast as C-extensions.

  • Versions: 13
  • Dependent Packages: 43
  • Dependent Repositories: 346
Rankings
Dependent repos count: 1.6%
Dependent packages count: 1.6%
Average: 5.9%
Stargazers count: 7.5%
Forks count: 12.9%
Last synced: 4 months ago
anaconda.org: sortedcontainers

SortedContainers is a sorted collections library, written in pure-Python and fast as C-extensions.

  • Versions: 11
  • Dependent Packages: 11
  • Dependent Repositories: 346
Rankings
Dependent packages count: 3.7%
Dependent repos count: 9.3%
Average: 13.0%
Stargazers count: 15.3%
Forks count: 23.7%
Last synced: 4 months ago

Dependencies

requirements.txt pypi
  • bintrees *
  • blist *
  • coverage *
  • cython *
  • doc8 *
  • gj *
  • matplotlib *
  • pyannote-banyan *
  • pylint *
  • pytest *
  • pytest-cov *
  • rstcheck *
  • scipy *
  • skiplistcollections *
  • sphinx *
  • tox *
  • treap *
  • twine *
  • wheel *
.github/workflows/integration.yml actions
  • actions/checkout v3 composite
  • actions/setup-python v4 composite
.github/workflows/release.yml actions
  • actions/checkout v3 composite
  • actions/setup-python v4 composite
  • pypa/gh-action-pypi-publish release/v1 composite
pyproject.toml pypi