Skip to main content

Official Python client for myip.foo - free IP lookup API with geolocation

Project description

myip-foo

Official Python client for myip.foo - a free, privacy-focused IP lookup API.

PyPI version Python versions License: MIT

Features

  • Full type hints (PEP 561)
  • Zero dependencies (async requires aiohttp)
  • Dual-stack IPv4/IPv6 support
  • Connection type detection
  • No API key required

Installation

pip install myip-foo

# With async support
pip install myip-foo[async]

Quick Start

from myip_foo import get_ip, get_ip_data, get_dual_stack

# Get plain IP
ip = get_ip()
print(ip)  # "203.0.113.42"

# Get full data with geolocation
data = get_ip_data()
print(data['ip'])                    # "203.0.113.42"
print(data['location']['city'])      # "Amsterdam"
print(data['location']['country'])   # "NL"
print(data['network']['isp'])        # "KPN B.V."
print(data['connectionType'])        # "residential"

# Get both IPv4 and IPv6
dual = get_dual_stack()
print(dual['ipv4'])  # "203.0.113.42"
print(dual['ipv6'])  # "2001:db8::1" or None

API Reference

Functions

get_ip() -> str

Returns your IP address as plain text.

get_ip_data() -> IPData

Returns full IP data including geolocation.

get_dual_stack(timeout: int = 5) -> DualStackData

Returns both IPv4 and IPv6 addresses.

get_connection_type() -> ConnectionTypeData

Detects if connection is residential, VPN, or datacenter.

get_headers() -> dict[str, str]

Returns all HTTP headers as seen by the server.

get_user_agent() -> str

Returns your user agent string.

Async Functions

Install with pip install myip-foo[async] to use async versions:

import asyncio
from myip_foo import get_ip_async, get_ip_data_async, get_dual_stack_async

async def main():
    ip = await get_ip_async()
    data = await get_ip_data_async()
    dual = await get_dual_stack_async()
    print(f"IP: {ip}, City: {data['location']['city']}")

asyncio.run(main())

Types

class IPData(TypedDict):
    ip: str
    type: str  # "IPv4" or "IPv6"
    hostname: Optional[str]
    connectionType: Optional[str]  # "residential", "vpn", "datacenter", "tor"
    location: Location
    network: Network
    cloudflare: Cloudflare

class DualStackData(TypedDict):
    ipv4: Optional[str]
    ipv6: Optional[str]

class ConnectionTypeData(TypedDict):
    ip: str
    type: str  # "residential", "vpn", "datacenter", "unknown"

Dual-Stack Endpoints

The get_dual_stack() function uses dedicated subdomains:

  • ipv4.myip.foo/ip - Returns IPv4 only (A record)
  • ipv6.myip.foo/ip - Returns IPv6 only (AAAA record)

Privacy

myip.foo does not log IP addresses or use cookies. See Privacy Policy.

Links

License

MIT License - see LICENSE for details.

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

myip_foo-1.0.0.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

myip_foo-1.0.0-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file myip_foo-1.0.0.tar.gz.

File metadata

  • Download URL: myip_foo-1.0.0.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for myip_foo-1.0.0.tar.gz
Algorithm Hash digest
SHA256 6abbc4a4ad257f88ef36a3ed6ce5269075d9e6556e1db3ad1247eb1fe453db00
MD5 571981ca1f9f8c88a2360cd15f6db0f0
BLAKE2b-256 0f4a8fe97b7c6e4a0d8a7ad7335ac73214299ba47b67e9ae141c1c1e87cffe68

See more details on using hashes here.

File details

Details for the file myip_foo-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: myip_foo-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for myip_foo-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b24c894d7de82243bc8b77bb57304d2219ef2434844eac75d2caeac14ab31e52
MD5 00159af18531666fa13b252c2c4d9fac
BLAKE2b-256 689c8cf18f37be03d3b438519b5939f23df5a3e9c9c93eeee2424e423c57bb29

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page