Skip to main content

Redis as a storage for IP range

Project description

License: MIT PyPI version


Store IP Ranges in Redis as sorted sets for fast retrieval


pip install iprange-python


from iprange import IPRange

iprange = IPRange()

# Add a new range with some metadata
iprange.add('', {'some': 'data', 'more': 'metadata'})

# Find the most specific range that contains a specific IP
# => {'range': '', 'some': 'data', 'more': 'metadata'}

# Find all ranges that contains a specific IP
# => [{'range': '', 'some': 'data', 'more': 'metadata'}]

# Delete the range

You can use it with Redis Cluster too:

from iprange import IPRange

# Requires at least one node for cluster discovery. Multiple nodes is recommended.
startup_nodes = [{'host': '', 'port': 16379}]
iprange = IPRange(redis_cluster=True, startup_nodes=startup_nodes)

# ...

IPRange in other languages


This library relies on a Redis fork that implements interval sets, as described in this blog post.

You can also use a more recent version of Redis with Interval Sets.

Project details

Download files

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

Files for iprange-python, version 0.0.8
Filename, size File type Python version Upload date Hashes
Filename, size iprange-python-0.0.8.tar.gz (3.3 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page