Skip to main content

Fast, pure Python indexable skip list

Project description

PySkipList is a fast, pure Python implementation of an indexable skiplist. It implements a SkipList data structure that provides an always sorted, list-like data structure for (key, value) pairs. It efficiently supports the following operations:

  • Insert a pair in the list, maintaining sorted order.

  • Find the value of a given key.

  • Remove a given pair based on a key.

  • Iterate over all pairs in sorted order.

  • Find the position of a given key.

  • Access a pair at a certain position.

  • Delete a pair at a certain position.

Since PySkipList is a pure Python implementation, it should work well on alternative Python implementations such as PyPy and Jython.


The following provides a few examples on how to use the SkipList API:

>>> from pyskiplist import SkipList
>>> sl = SkipList()
>>> sl.insert('foo', 'bar')
>>> sl.insert('baz', 'qux')
>>> sl
SkipList((('baz', 'qux'), ('foo', 'bar')))
>>> sl[0]
('baz', 'qux')
>>> sl.remove('foo')  # remove by key
>>> del sl[0]  # remove by position

Asymptotic Complexity

Below are the Big-O complexities of the various operations implemented by pyskiplist:




O(log N)

search by key

O(log N)

removal by key

O(log N)

forward iteration


find by position

O(log N)

access by position

O(log N)

delete by position

O(log N)


Below are the results of some performance tests. These are for Python 3.4.2 on my Linux laptop:


Operations / second

Insert @ 1k nodes


Insert @ 10k nodes


Insert @ 100k nodes


Remove @ 1k nodes


Remove @ 10k nodes


Remove @ 100k nodes


Search @ 1k nodes


Search @ 10k nodes


Search @ 100k nodes


Memory usage

PySkipList tries to be efficient with regards to memory usage. The numbers below are for Python 3.4.2 on my Linux laptop. This specific test stores pairs of integer keys and an integer values in a skiplist. The total size of the two integers on this Python version is 56 bytes.


Bytes / node

Overhead (fixed)










Implementation notes

Reference papers on skiplists:

This implementation uses a novel (as far as I know) technique where it stores just a single link width per node, and only in nodes with level > 0. The link corresponds to the number of nodes skipped by the highest incoming link. Other implementations that I’ve seen all store a width for every link. This approach saves a lot of memory. The overhead should just be 1/e (0.37) integers per node. It makes an indexable skiplist almost as memory efficient as its non-indexable cousin.

Duplicate keys are allowed in this implementation, and insertion order is maintained.

Skiplist nodes are implemented as plain lists instead of objects. This saves memory. Kudos to for the idea.

The built-in Mersenne Twister is used as the random source. This is preferable over SystemRandom since it doesn’t require a system call and there is no need for cryptographically secure numbers.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyskiplist-1.0.0.tar.gz (8.0 kB view hashes)

Uploaded source

Built Distribution

pyskiplist-1.0.0-py2.py3-none-any.whl (8.6 kB view hashes)

Uploaded py2 py3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page