Skip to main content

The official python interface to GeoIP.Network

Project description

GeoIP.Network Python Library

Release Badge Pipeline Badge

The official python interface to GeoIP.Network

Screenshot of example code below

Localize IP addresses instantly anywhere in the world.

Improve your customer’s experience and optimize your marketing by using GeoIP.Network to discover your client’s location in real-time.

Our API is free to use for up to 10,000 requests per day (more than most commercial projects offer per month in their paid packages) - or unlimited if you sponsor the project for the cost of a cup of coffee per month. Discover details like ISP, Country, and Location instantly. GeoIP.Network is a Not-For-Profit (and open-source) project that aims to provide reliable and accurate IP localization data for free to everyone. Building on research done at world leading universities, we use a blend of information from the Internet Routing Registry (IRR), live BGP streams, and a stochastic-progressive latency measurement algorithm to provide the most up-to-date and accurate data possible.

TLDR; We use science and public data and offer accurate GeoIP data for free.

Usage (free < 10000 requests / day):

NOTE: The following IP addresses are Documentation addresses. As such you will need to replace them with valid public IP addresses for these examples to work.

import geoip_network
# Single IP
result = geoip_network.lookup_ip("198.51.100.1")
print(result.to_dict())
# {"allocated_cc": "--", "as-name": "Documentation ASN", "asn": "AS64496", "cidr": "198.51.100.0/24", "geo": {"geometry": {"coordinates": [-112.404207, 45.73643438], "type": "Point"}, "properties": {"radius": 0.0}, "type": "Feature"}, "rir": "IANA", "timestamp": 1643422555},

# IP Range (CIDR)
result = geoip_network.lookup_cidr("198.51.100.0/24")
print(result.to_dict())
# {"allocated_cc": "--", "as-name": "Documentation ASN", "asn": "AS64496", "cidr": "198.51.100.0/24", "geo": {"geometry": {"coordinates": [-112.404207, 45.73643438], "type": "Point"}, "properties": {"radius": 0.0}, "type": "Feature"}, "rir": "IANA", "timestamp": 1643422555},

# Bulk lookup
for result in geoip_network.lookup_bulk(["2001:db8::/48", "198.51.100.1", "0.0.0.0/24"]):
    print(result.to_dict())
# {"allocated_cc": "--", "as-name": "Documentation ASN", "asn": "AS64496", "cidr": "2001:db8::/32", "geo": {"geometry": {"coordinates": [16.72425629, 62.88018421], "type": "Point"}, "properties": {"radius": 0.0}, "type": "Feature"}, "rir": "IANA", "timestamp": 1634593342},
# {"allocated_cc": "--", "as-name": "Documentation ASN", "asn": "AS64496", "cidr": "198.51.100.0/24", "geo": {"geometry": {"coordinates": [-112.404207, 45.73643438], "type": "Point"}, "properties": {"radius": 0.0}, "type": "Feature"}, "rir": "IANA", "timestamp": 1643422555},
# {"error": "no covering prefix found"}

Usage (sponsor):

NOTE: The following IP addresses are Documentation addresses. As such you will need to replace them with valid public IP addresses for these examples to work.

import geoip_network
# Login

geoip = geoip_network.GeoIP("api_username", "api_password")
# Single IP

result = geoip.lookup_ip("198.51.100.1")
print(result.to_dict())
# {"allocated_cc": "--", "as-name": "Documentation ASN", "asn": "AS64496", "cidr": "198.51.100.0/24", "geo": {"geometry": {"coordinates": [-112.404207, 45.73643438], "type": "Point"}, "properties": {"radius": 0.0}, "type": "Feature"}, "rir": "IANA", "timestamp": 1643422555},

# IP Range (CIDR)
result = geoip.lookup_cidr("198.51.100.0/24")
print(result.to_dict())
# {"allocated_cc": "--", "as-name": "Documentation ASN", "asn": "AS64496", "cidr": "198.51.100.0/24", "geo": {"geometry": {"coordinates": [-112.404207, 45.73643438], "type": "Point"}, "properties": {"radius": 0.0}, "type": "Feature"}, "rir": "IANA", "timestamp": 1643422555},

# Bulk lookup
for result in geoip.lookup_bulk(["2001:db8::/48", "198.51.100.1", "0.0.0.0/24"]):
    print(result.to_dict())
# {"allocated_cc": "--", "as-name": "Documentation ASN", "asn": "AS64496", "cidr": "2001:db8::/32", "geo": {"geometry": {"coordinates": [16.72425629, 62.88018421], "type": "Point"}, "properties": {"radius": 0.0}, "type": "Feature"}, "rir": "IANA", "timestamp": 1634593342},
# {"allocated_cc": "--", "as-name": "Documentation ASN", "asn": "AS64496", "cidr": "198.51.100.0/24", "geo": {"geometry": {"coordinates": [-112.404207, 45.73643438], "type": "Point"}, "properties": {"radius": 0.0}, "type": "Feature"}, "rir": "IANA", "timestamp": 1643422555},
# {"error": "no covering prefix found"}

Alternatively

NOTE: The following IP addresses are Documentation addresses. As such you will need to replace them with valid public IP addresses for these examples to work.

import geoip_network
# Single IP

result = geoip_network.lookup_ip("198.51.100.1", auth="<bearer_token>")
print(result.to_dict())
# {"allocated_cc": "--", "as-name": "Documentation ASN", "asn": "AS64496", "cidr": "198.51.100.0/24", "geo": {"geometry": {"coordinates": [-112.404207, 45.73643438], "type": "Point"}, "properties": {"radius": 0.0}, "type": "Feature"}, "rir": "IANA", "timestamp": 1643422555},

# IP Range (CIDR)
result = geoip_network.lookup_cidr("198.51.100.0/24", auth="<bearer_token>")
print(result.to_dict())
# {"allocated_cc": "--", "as-name": "Documentation ASN", "asn": "AS64496", "cidr": "198.51.100.0/24", "geo": {"geometry": {"coordinates": [-112.404207, 45.73643438], "type": "Point"}, "properties": {"radius": 0.0}, "type": "Feature"}, "rir": "IANA", "timestamp": 1643422555},

# Bulk lookup
for result in geoip_network.lookup_bulk(["2001:db8::/48", "198.51.100.1", "0.0.0.0/24"], auth="<bearer_token>"):
    print(result.to_dict())
# {"allocated_cc": "--", "as-name": "Documentation ASN", "asn": "AS64496", "cidr": "2001:db8::/32", "geo": {"geometry": {"coordinates": [16.72425629, 62.88018421], "type": "Point"}, "properties": {"radius": 0.0}, "type": "Feature"}, "rir": "IANA", "timestamp": 1634593342},
# {"allocated_cc": "--", "as-name": "Documentation ASN", "asn": "AS64496", "cidr": "198.51.100.0/24", "geo": {"geometry": {"coordinates": [-112.404207, 45.73643438], "type": "Point"}, "properties": {"radius": 0.0}, "type": "Feature"}, "rir": "IANA", "timestamp": 1643422555},
# {"error": "no covering prefix found"}

Installation (from pip):

pip install geoip_network

Installation (from source):

git clone https://gitlab.com/geoip.network/python-library
poetry install

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

GeoIP-Network-0.1.3.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

GeoIP_Network-0.1.3-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file GeoIP-Network-0.1.3.tar.gz.

File metadata

  • Download URL: GeoIP-Network-0.1.3.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.9.12 Linux/5.4.109+

File hashes

Hashes for GeoIP-Network-0.1.3.tar.gz
Algorithm Hash digest
SHA256 0ae4d4185520319d18d0fa9d3fdd75643b9aea0424827953e80e30a4f587d69d
MD5 a16f53ba3dfe55ae48491414ad633514
BLAKE2b-256 44123ec7272b3a5e1ef83b229697afbac78fad30851429fe64a77f8b79315a76

See more details on using hashes here.

File details

Details for the file GeoIP_Network-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: GeoIP_Network-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.9.12 Linux/5.4.109+

File hashes

Hashes for GeoIP_Network-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 60e059a32236691a4eca21ae3ff621844b678ef42d5d9766d49ebea563381b0b
MD5 ad642dc2a417b194b57a0ccf17cf847f
BLAKE2b-256 2cb3a958a1b19c31788f50b9b1c217ff3147f8230498435e68cd84cf741a0626

See more details on using hashes here.

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