No project description provided
Project description
Polars MaxMindDB Lookup Plugin
This plugin extends the functionality of Polars by providing methods to look up IP address information using MaxMind databases. It supports city, country, and ASN lookups.
Features
- City Lookup: Retrieves city-level information for a given IP address as a string.
- Country Lookup: Retrieves country-level information for a given IP address as a string.
- ASN Lookup: Retrieves ASN (Autonomous System Number) name for a given IP address as a string.
- Integration with Polars: Works seamlessly with Polars DataFrames, offering fast processing.
Requirements
- Python 3.8+
- Polars library
Install Polars with:
uv add polars
- MaxMindDB: Download and use the GeoIP2 databases provided by MaxMind (e.g., GeoLite2-City.mmdb, GeoLite2-Country.mmdb, GeoLite2-ASN.mmdb). See MaxMind for more details.
Installation
Add the plugin to your project. Install it directly from the repository or manually include the Python file.
uv add polars-maxminddb
Usage
Example Code
import polars as pl
from polars_maxminddb import ip_lookup_city, ip_lookup_country, ip_lookup_asn
# Example DataFrame with IP addresses
df = pl.DataFrame({
"ip_addresses": ["92.200.50.6", "195.90.212.198", "95.173.223.186", "121.37.156.226"],
})
# Perform city lookup
df = df.with_columns(
ip_lookup_city(df["ip_addresses"]).alias("city")
)
# Perform country lookup
df = df.with_columns(
ip_lookup_country(df["ip_addresses"]).alias("country")
)
# Perform ASN lookup
df = df.with_columns(
ip_lookup_asn(df["ip_addresses"]).alias("asn_name")
)
print(df)
Output
The output will include the city, country, and ASN name information as strings. For example:
shape: (4, 4)
┌────────────────┬───────────────────┬─────────┬─────────────────────────────────┐
│ ip ┆ city ┆ country ┆ asn_name │
│ --- ┆ --- ┆ --- ┆ --- │
│ str ┆ str ┆ str ┆ str │
╞════════════════╪═══════════════════╪═════════╪═════════════════════════════════╡
│ 92.200.50.6 ┆ Sundern ┆ Germany ┆ Plusnet GmbH │
│ 195.90.212.198 ┆ Frankfurt am Main ┆ Germany ┆ EVANZO e-commerce GmbH │
│ 95.173.223.186 ┆ Lima ┆ Peru ┆ Datacamp Limited │
│ 121.37.156.226 ┆ ┆ China ┆ Huawei Cloud Service data cent… │
└────────────────┴───────────────────┴─────────┴─────────────────────────────────┘
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file polars_maxminddb-0.2.3.tar.gz.
File metadata
- Download URL: polars_maxminddb-0.2.3.tar.gz
- Upload date:
- Size: 18.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.7.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
62d8b46321fb14dd60fa75ca79b6f50b3895c65656d0444aaab53eb99c8400e5
|
|
| MD5 |
e75befb6388423578801caf308510428
|
|
| BLAKE2b-256 |
3e6a8cd6401b80e42a02e083dcb1df2cc09a76cbfc0789ddb492c3288bebda18
|
File details
Details for the file polars_maxminddb-0.2.3-cp38-abi3-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: polars_maxminddb-0.2.3-cp38-abi3-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 3.9 MB
- Tags: CPython 3.8+, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.7.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
327ab16e7dfbe5637f8d000d5d120b628d6d23509acf6a60900e34fe7948ec59
|
|
| MD5 |
e70eb62afeeae7e97a4bed2073009a50
|
|
| BLAKE2b-256 |
95f41242b2cb24abdb20df1325fa18905f69bd0e6abed4717f65cb18123374ba
|