Skip to main content

No project description provided

Project description

Polars IPTools

Polars IPTools is a Rust-based extension to accelerates IP address manipulation and enrichment in Polars dataframes. This library includes various utility functions for working with IPv4 and IPv6 addresses and geoip enrichment using MaxMind databases.

Install

pip install polars-iptools

Examples

Simple enrichments

IPTools' Rust implementation gives you speedy answers to basic IP questions like "is this a private IP?"

>>> import polars as pl
>>> import polars_iptools as ip
>>> df = pl.DataFrame({'ip': ['8.8.8.8', '2606:4700::1111', '192.168.100.100', '172.21.1.1', '172.34.5.5', 'a.b.c.d']})
>>> df.with_columns(ip.is_private(pl.col('ip')).alias('is_private'))
shape: (6, 2)
┌─────────────────┬────────────┐
 ip               is_private 
 ---              ---        
 str              bool       
╞═════════════════╪════════════╡
 8.8.8.8          false      
 2606:4700::1111  false      
 192.168.100.100  true       
 172.21.1.1       true       
 172.34.5.5       false      
 a.b.c.d          false      
└─────────────────┴────────────┘

is_in but for network ranges

Pandas and Polars have is_in functions to perform membership lookups. IPTools extends this to enable IP address membership in IP networks. This function works seamlessly with both IPv4 and IPv6 addresses and converts the specified networks into a Level-Compressed trie (LC-Trie) for fast, efficient lookups.

>>> import polars as pl
>>> import polars_iptools as ip
>>> df = pl.DataFrame({'ip': ['8.8.8.8', '1.1.1.1', '2606:4700::1111']})
>>> networks = ['8.8.8.0/24', '2606:4700::/32']
>>> df.with_columns(ip.is_in(pl.col('ip'), networks).alias('is_in'))
shape: (3, 2)
┌─────────────────┬───────┐
 ip               is_in 
 ---              ---   
 str              bool  
╞═════════════════╪═══════╡
 8.8.8.8          true  
 1.1.1.1          false 
 2606:4700::1111  true  
└─────────────────┴───────┘

GeoIP enrichment

Using MaxMind's GeoLite2-ASN.mmdb and GeoLite2-City.mmdb databases, IPTools provides offline enrichment of network ownership and geolocation.

ip.geoip.full returns a Polars struct containing all available metadata parameters. If you just want the ASN and AS organization, you can use ip.geoip.asn.

>>> import polars as pl
>>> import polars_iptools as ip

>>> df = pl.DataFrame({"ip":["8.8.8.8", "192.168.1.1", "2606:4700::1111", "999.abc.def.123"]})
>>> df.with_columns([ip.geoip.full(pl.col("ip")).alias("geoip")])

shape: (4, 2)
┌─────────────────┬─────────────────────────────────┐
 ip               geoip                           
 ---              ---                             
 str              struct[11]                      
╞═════════════════╪═════════════════════════════════╡
 8.8.8.8          {15169,"GOOGLE","","NA","","", 
 192.168.1.1      {0,"","","","","","","",0.0,0. 
 2606:4700::1111  {13335,"CLOUDFLARENET","","","… │
 999.abc.def.123  {null,null,null,null,null,null 
└─────────────────┴─────────────────────────────────┘

>>> df.with_columns([ip.geoip.asn(pl.col("ip")).alias("asn")])
shape: (4, 2)
┌─────────────────┬───────────────────────┐
 ip               asn                   
 ---              ---                   
 str              str                   
╞═════════════════╪═══════════════════════╡
 8.8.8.8          AS15169 GOOGLE        
 192.168.1.1                            
 2606:4700::1111  AS13335 CLOUDFLARENET 
 999.abc.def.123                        
└─────────────────┴───────────────────────┘

Environment Configuration

IPTools uses two MaxMind databases: GeoLite2-ASN.mmdb and GeoLite2-City.mmdb. You only need these files if you call the geoip functions.

Set the MAXMIND_MMDB_DIR environment variable to tell the extension where these files are located.

export MAXMIND_MMDB_DIR=/path/to/your/mmdb/files
# or Windows users
set MAXMIND_MMDB_DIR=c:\path\to\your\mmdb\files

If the environment is not set, polars_iptools will check two other common locations (on Mac/Linux):

/usr/local/share/GeoIP
/opt/homebrew/var/GeoIP

Credit

Developing this extension was super easy by following Marco Gorelli's tutorial and cookiecutter template.

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

polars_iptools-0.1.5.tar.gz (46.1 kB view details)

Uploaded Source

Built Distributions

polars_iptools-0.1.5-cp38-abi3-win_amd64.whl (3.5 MB view details)

Uploaded CPython 3.8+ Windows x86-64

polars_iptools-0.1.5-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.5 MB view details)

Uploaded CPython 3.8+ manylinux: glibc 2.17+ x86-64

polars_iptools-0.1.5-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl (3.7 MB view details)

Uploaded CPython 3.8+ manylinux: glibc 2.17+ i686

polars_iptools-0.1.5-cp38-abi3-macosx_11_0_arm64.whl (2.8 MB view details)

Uploaded CPython 3.8+ macOS 11.0+ ARM64

polars_iptools-0.1.5-cp38-abi3-macosx_10_12_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.8+ macOS 10.12+ x86-64

File details

Details for the file polars_iptools-0.1.5.tar.gz.

File metadata

  • Download URL: polars_iptools-0.1.5.tar.gz
  • Upload date:
  • Size: 46.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.7.0

File hashes

Hashes for polars_iptools-0.1.5.tar.gz
Algorithm Hash digest
SHA256 d907873b3f6e523f3eb52a35813b28a6d51069ae4dbc64043488f38d81224146
MD5 b8c3fed3591d8e4f8301a8c11572fa4e
BLAKE2b-256 4828efe6a7854c187f4fb06d862dbb84de3647229b8e8a8f47b8f828867abbe3

See more details on using hashes here.

Provenance

File details

Details for the file polars_iptools-0.1.5-cp38-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for polars_iptools-0.1.5-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 668a90f5535ef67daa4e1c2228783a19b19c6f7d268b3f5f5679728bc4f1a344
MD5 4bbbcd92629fecc164b43e832423780e
BLAKE2b-256 f9c4b12703528fafe88eea2ef79d3205594f9c701d67d366b27abe4bd17ac273

See more details on using hashes here.

Provenance

File details

Details for the file polars_iptools-0.1.5-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for polars_iptools-0.1.5-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2a1ffe941265b0c3ad13b2e6c07345eaec330fa1c6ce59593571429937b85ffe
MD5 c8132856a74654edf7b7cbbdcf557c54
BLAKE2b-256 4ba04bad828b2c2ec749c4a98578f8f50a7315fb201dae28f994fca451492788

See more details on using hashes here.

Provenance

File details

Details for the file polars_iptools-0.1.5-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for polars_iptools-0.1.5-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 95e75ecd3cc6c5805c753e5181e172f2c9a2fc6778cb70e31619d7cd1e539d4f
MD5 2c0dd4679d8f12ea2e1269c6d80c0e28
BLAKE2b-256 f99da3e55c01c10bbe51c71849dedd2a01c02083870d349763cf7db984892937

See more details on using hashes here.

Provenance

File details

Details for the file polars_iptools-0.1.5-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for polars_iptools-0.1.5-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1ed01ef0384e9349ca528537148199bad8292af023386934fd992fb604611300
MD5 e733bc07d55e6fd625e098201339c144
BLAKE2b-256 a13d7f146a208f073026f689358e52f3343f8108c7592f88e23443bc9da4f9cf

See more details on using hashes here.

Provenance

File details

Details for the file polars_iptools-0.1.5-cp38-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for polars_iptools-0.1.5-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 8a9dacb1e52ad46a0ba5288f09ce34cec4fc07a930dd8c67d5b7ca09251a8842
MD5 a9a16c11198cee13bb791fc82a469eb3
BLAKE2b-256 5f88a4999d88848a4dde3b01ffd11719de3adaaf0bed0748b56f10b440e654a2

See more details on using hashes here.

Provenance

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