Skip to main content

Redis as a storage for IP range

Project description

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![PyPI version](https://badge.fury.io/py/iprange-python.svg)](https://badge.fury.io/py/iprange-python)

# IPRange

Store IP Ranges in Redis as sorted sets for fast retrieval

## Installation

pip install iprange-python

## Usage

```python
from iprange import IPRange

iprange = IPRange()

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

# Find the most specific range that contains a specific IP
iprange.find('192.168.0.20')
# => {'range': '192.168.0.1/24', 'some': 'data', 'more': 'metadata'}

# Find all ranges that contains a specific IP
iprange.find_all('192.168.0.20')
# => [{'range': '192.168.0.1/24', 'some': 'data', 'more': 'metadata'}]

# Delete the range
iprange.remove('192.168.0.1/24')
```

## IPRange in other languages

- [Ruby](https://github.com/globocom/iprange)

## Notice

This library relies on [a Redis fork that implements interval sets](https://github.com/hoxworth/redis/tree/2.6-intervals),
as described in this [blog post](http://blog.togo.io/how-to/adding-interval-sets-to-redis/).

You can also use [a more recent version of Redis with Interval Sets](https://github.com/lucasrodcosta/redis).

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

iprange-python-0.0.6.tar.gz (2.9 kB view hashes)

Uploaded Source

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