{"id":13593885,"url":"https://github.com/ipinfo/python","last_synced_at":"2025-06-16T11:10:59.840Z","repository":{"id":41055350,"uuid":"145909218","full_name":"ipinfo/python","owner":"ipinfo","description":"Official Python Library for IPinfo API (IP geolocation and other types of IP data)","archived":false,"fork":false,"pushed_at":"2025-05-08T17:44:03.000Z","size":223,"stargazers_count":513,"open_issues_count":7,"forks_count":114,"subscribers_count":32,"default_branch":"master","last_synced_at":"2025-06-13T11:55:45.493Z","etag":null,"topics":["ip-address","ip-data","ip-geolocation","ipinfo","python"],"latest_commit_sha":null,"homepage":"https://ipinfo.io","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ipinfo.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-08-23T21:30:09.000Z","updated_at":"2025-06-11T10:47:57.000Z","dependencies_parsed_at":"2023-10-16T22:27:27.107Z","dependency_job_id":"3f9fe299-38f8-4e2c-af4e-db3540666a0f","html_url":"https://github.com/ipinfo/python","commit_stats":{"total_commits":124,"total_committers":13,"mean_commits":9.538461538461538,"dds":0.7419354838709677,"last_synced_commit":"f591515c376d4dc0a4751a82456a1f2aa49e747c"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"purl":"pkg:github/ipinfo/python","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipinfo%2Fpython","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipinfo%2Fpython/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipinfo%2Fpython/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipinfo%2Fpython/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ipinfo","download_url":"https://codeload.github.com/ipinfo/python/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipinfo%2Fpython/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260148401,"owners_count":22965915,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ip-address","ip-data","ip-geolocation","ipinfo","python"],"created_at":"2024-08-01T16:01:25.840Z","updated_at":"2025-06-16T11:10:59.826Z","avatar_url":"https://github.com/ipinfo.png","language":"Python","readme":"# [\u003cimg src=\"https://ipinfo.io/static/ipinfo-small.svg\" alt=\"IPinfo\" width=\"24\"/\u003e](https://ipinfo.io/) IPinfo Python Client Library\n\nThis is the official Python client library for the IPinfo.io IP address API, allowing you to look up your own IP address, or get any of the following details for an IP:\n\n - [IP geolocation](https://ipinfo.io/ip-geolocation-api) (city, region, country, postal code, latitude, and longitude)\n - [ASN details](https://ipinfo.io/asn-api) (ISP or network operator, associated domain name, and type, such as business, hosting, or company)\n - [Firmographics data](https://ipinfo.io/ip-company-api) (the name and domain of the business that uses the IP address)\n - [Carrier information](https://ipinfo.io/ip-carrier-api) (the name of the mobile carrier and MNC and MCC for that carrier if the IP is used exclusively for mobile traffic)\n\n## Getting Started\n\nYou'll need an IPinfo API access token, which you can get by signing up for a free account at [https://ipinfo.io/signup](https://ipinfo.io/signup).\n\nThe free plan is limited to 50,000 requests per month, and doesn't include some of the data fields such as IP type and company data. To enable all the data fields and additional request volumes see [https://ipinfo.io/pricing](https://ipinfo.io/pricing)\n\n⚠️ Note: This library does not currently support our newest free API https://ipinfo.io/lite. If you’d like to use IPinfo Lite, you can call the [endpoint directly](https://ipinfo.io/developers/lite-api) using your preferred HTTP client. Developers are also welcome to contribute support for Lite by submitting a pull request.\n\n### Installation\n\nThis package works with Python 3.5 or greater. However, we only officially\nsupport non-EOL Python versions.\n\n```bash\npip install ipinfo\n```\n\n### Quick Start\n\n```python\n\u003e\u003e\u003e import ipinfo\n\u003e\u003e\u003e access_token = '123456789abc'\n\u003e\u003e\u003e handler = ipinfo.getHandler(access_token)\n\u003e\u003e\u003e ip_address = '216.239.36.21'\n\u003e\u003e\u003e details = handler.getDetails(ip_address)\n\u003e\u003e\u003e details.city\n'Mountain View'\n\u003e\u003e\u003e details.loc\n'37.3861,-122.0840'\n```\n\n#### Async/Await\n\nAn asynchronous handler is available as well, and can be accessed and used in\nalmost the same exact way as the synchronous handler:\n\n```python\n\u003e\u003e\u003e import ipinfo\n\u003e\u003e\u003e access_token = '123456789abc'\n\u003e\u003e\u003e handler = ipinfo.getHandlerAsync(access_token)\n\u003e\u003e\u003e ip_address = '216.239.36.21'\n\u003e\u003e\u003e async def do_req():\n...     details = await handler.getDetails(ip_address)\n...     print(details.city)\n...     print(details.loc)\n...\n\u003e\u003e\u003e\n\u003e\u003e\u003e import asyncio\n\u003e\u003e\u003e loop = asyncio.get_event_loop()\n\u003e\u003e\u003e loop.run_until_complete(do_req())\nMountain View\n37.4056,-122.0775\n\u003e\u003e\u003e\n\u003e\u003e\u003e ip_address = '1.1.1.1'\n\u003e\u003e\u003e loop.run_until_complete(do_req())\nNew York City\n40.7143,-74.0060\n```\n\nInternally the library uses `aiohttp`, but as long as you provide an event\nloop (as in this example via `asyncio`), it shouldn't matter.\n\n### Usage\n\nThe `Handler.getDetails()` method accepts an IP address as an optional, positional argument. If no IP address is specified, the API will return data for the IP address from which it receives the request.\n\n```python\n\u003e\u003e\u003e import ipinfo\n\u003e\u003e\u003e access_token = '123456789abc'\n\u003e\u003e\u003e handler = ipinfo.getHandler(access_token)\n\u003e\u003e\u003e details = handler.getDetails()\n\u003e\u003e\u003e details.city\n'Mountain View'\n\u003e\u003e\u003e details.loc\n'37.3861,-122.0840'\n```\n\n### Authentication\n\nThe IPinfo library can be authenticated with your IPinfo API token, which is passed in as a positional argument. It also works without an authentication token, but in a more limited capacity.\n\n```python\n\u003e\u003e\u003e import ipinfo\n\u003e\u003e\u003e handler = ipinfo.getHandler(access_token='123456789abc')\n```\n\n### Details Data\n\n`handler.getDetails()` will return a `Details` object that contains all fields listed in the [IPinfo developer docs](https://ipinfo.io/developers/responses#full-response) with a few minor additions. Properties can be accessed directly.\n\n```python\n\u003e\u003e\u003e details.hostname\n'any-in-2415.1e100.net'\n```\n\n#### Country Name\n\n`details.country_name` will return the country name, as supplied by the `countries.json` file. See below for instructions on changing that file for use with non-English languages. `details.country` will still return a country code.\n\n```python\n\u003e\u003e\u003e details.country\n'US'\n\u003e\u003e\u003e details.country_name\n'United States'\n```\n\n#### Longitude and Latitude\n\n`details.latitude` and `details.longitude` will return latitude and longitude, respectively, as strings. `details.loc` will still return a composite string of both values.\n\n```python\n\u003e\u003e\u003e details.loc\n'37.3861,-122.0840'\n\u003e\u003e\u003e details.latitude\n'37.3861'\n\u003e\u003e\u003e details.longitude\n'-122.0840'\n```\n\n#### Accessing all properties\n\n`details.all` will return all details data as a dictionary.\n\n```python\n\u003e\u003e\u003e import pprint\n\u003e\u003e\u003e pprint.pprint(details.all)\n{'abuse': {'address': 'US, CA, Mountain View, 1600 Amphitheatre Parkway, 94043',\n           'country': 'US',\n           'email': 'network-abuse@google.com',\n           'name': 'Abuse',\n           'network': '216.239.32.0/19',\n           'phone': '+1-650-253-0000'},\n 'asn': {'asn': 'AS15169',\n         'domain': 'google.com',\n         'name': 'Google LLC',\n         'route': '216.239.36.0/24',\n         'type': 'business'},\n 'city': 'Mountain View',\n 'company': {'domain': 'google.com', 'name': 'Google LLC', 'type': 'business'},\n 'country': 'US',\n 'country_name': 'United States',\n 'hosting': {'host': 'google',\n             'id': 'GOOGLE',\n             'name': 'Google LLC',\n             'network': '216.239.32.0/19'},\n 'hostname': 'any-in-2415.1e100.net',\n 'ip': '216.239.36.21',\n 'latitude': '37.3861',\n 'loc': '37.3861,-122.0840',\n 'longitude': '-122.0840',\n 'postal': '94035',\n 'region': 'California',\n 'timezone': 'America/Los_Angeles'}\n```\n\n### Caching\n\nIn-memory caching of `details` data is provided by default via the [cachetools](https://cachetools.readthedocs.io/en/latest/) library. This uses an LRU (least recently used) cache with a TTL (time to live) by default. This means that values will be cached for the specified duration; if the cache's max size is reached, cache values will be invalidated as necessary, starting with the oldest cached value.\n\n#### Modifying cache options\n\nCache behavior can be modified by setting the `cache_options` keyword argument. `cache_options` is a dictionary in which the keys are keyword arguments specified in the `cachetools` library. The nesting of keyword arguments is to prevent name collisions between this library and its dependencies.\n\n- Default maximum cache size: 4096 (multiples of 2 are recommended to increase efficiency)\n- Default TTL: 24 hours (in seconds)\n\n```python\n\u003e\u003e\u003e import ipinfo\n\u003e\u003e\u003e handler = ipinfo.getHandler(cache_options={'ttl':30, 'maxsize': 128})\n```\n\n#### Using a different cache\n\nIt's possible to use a custom cache by creating a child class of the [CacheInterface](https://github.com/ipinfo/python/blob/master/ipinfo/cache/interface.py) class and passing this into the handler object with the `cache` keyword argument. FYI this is known as [the Strategy Pattern](https://sourcemaking.com/design_patterns/strategy).\n\n```python\nimport ipinfo\nfrom ipinfo.cache.interface import CacheInterface\n\nclass MyCustomCache(CacheInterface):\n    ...\n\nhandler = ipinfo.getHandler(cache=MyCustomCache())\n```\n\n#### Accessing the cache directly\n\nYou can access/update the cache directly via dictionary-like notation.\n\n```python\n\u003e\u003e\u003e import ipinfo\n\u003e\u003e\u003e from ipinfo.handler_utils import cache_key\n\u003e\u003e\u003e\n\u003e\u003e\u003e access_token = '123456789abc'\n\u003e\u003e\u003e handler = ipinfo.getHandler(access_token)\n\u003e\u003e\u003e ip_cache_key = cache_key('1.1.1.1')\n\n# Check if IP is in the cache.\n\u003e\u003e\u003e ip_cache_key in handler.cache\nTrue\n\n# Get the IP's details from cache.\n\u003e\u003e\u003e handler.cache[ip_cache_key]\n{'ip': '1.1.1.1', 'hostname': 'one.one.one.one', 'anycast': True, 'city': 'Miami', 'region': 'Florida', 'country': 'US', 'loc': '25.7867,-80.1800', 'org': 'AS13335 Cloudflare, Inc.', 'postal': '33132', 'timezone': 'America/New_York', 'country_name': 'United States', 'latitude': '25.7867', 'longitude': '-80.1800'}\n\n# Set the IP's details to something else in the cache.\n\u003e\u003e\u003e handler.cache[ip_cache_key] = None\n\n# Delete the IP from the cache.\n\u003e\u003e\u003e del handler.cache[ip_cache_key]\n```\n\n### Modifying request options\n\n**Note**: the asynchronous handler currently only accepts the `timeout` option,\ninput the same way as shown below.\n\nRequest behavior can be modified by setting the `request_options` keyword argument. `request_options` is a dictionary in which the keys are keyword arguments specified in the `requests` library. The nesting of keyword arguments is to prevent name collisions between this library and its dependencies.\n\n- Default request timeout: 2 seconds\n\n```python\n\u003e\u003e\u003e handler = ipinfo.getHandler(request_options={'timeout': 4})\n```\n\n### Custom Headers\n\nYou can add custom headers or modify default headers by setting the `headers` keyword argument when initializing the handler. `headers` is a dictionary of `{'header': 'value'}` format.\n\n```python\n\u003e\u003e\u003e handler = ipinfo.getHandler(headers={'user-agent': 'My Custom User-agent', 'custom_header': 'yes'})\n```\n\n### Internationalization\n\nWhen looking up an IP address, the response object includes `details.country_name`, `details.isEU`, `details.country_flag`, `details.country_flag_url` and `details.country_currency` attributes which includes the country based on American English. It is possible to return the country name in other languages by setting the `countries`, remove or add EU countries by setting the keyword argument `eu_countries`, change the country flag emoji or unicode by setting the keyword argument `countries_flags` or change country's currency code or currency symbol by setting the `countries_currencies` when creating the `IPinfo` object. Moreover, the response object includes a `details.continent` which includes continent code and name of IP. The default file can be changed by setting the `continent` while creating the `IPinfo` object.\n\n```python\n\u003e\u003e\u003e import ipinfo\n# Country Names: In-memory map\n\u003e\u003e\u003e countries = {\n    \"BD\": \"Bangladesh\",\n    \"BE\": \"Belgium\",\n    \"BF\": \"Burkina Faso\",\n    ...\n}\n\n# EU Countries: In-memory list\n\u003e\u003e\u003e eu_countries = [\n    \"IE\",\n    \"AT\",\n    \"LT\",\n    ...\n]\n\n# Country Flags: In-memory map\n\u003e\u003e\u003e countries_flags = {\n    \"AD\": {\"emoji\": \"🇦🇩\", \"unicode\": \"U+1F1E6 U+1F1E9\"},\n    \"AE\": {\"emoji\": \"🇦🇪\", \"unicode\": \"U+1F1E6 U+1F1EA\"},\n    \"AF\": {\"emoji\": \"🇦🇫\", \"unicode\": \"U+1F1E6 U+1F1EB\"},\n    ...\n}\n\n# Country Currencies: In-memory map\n\u003e\u003e\u003e countries_currencies = {\n    \"AD\": {\"code\": \"EUR\", \"symbol\": \"€\"},\n    \"AE\": {\"code\": \"AED\", \"symbol\": \"د.إ\"},\n    \"AF\": {\"code\": \"AFN\", \"symbol\": \"؋\"},\n    ...\n}\n\n# Continents: In-memory map\n\u003e\u003e\u003e continents = {\n    \"BD\": {\"code\": \"AS\", \"name\": \"Asia\"},\n    \"BE\": {\"code\": \"EU\", \"name\": \"Europe\"},\n    \"BF\": {\"code\": \"AF\", \"name\": \"Africa\"},\n    ...\n}\n\n# create handler\n\u003e\u003e\u003e access_token = '123456789abc'\n\u003e\u003e\u003e handler = ipinfo.getHandler(\n    access_token,\n    countries=countries,\n    eu_countries=eu_countries,\n    countries_flags=countries_flags,\n    countries_currencies=countries_currencies,\n    continents=continents\n)\n```\n### Batch Operations\n\nLooking up a single IP at a time can be slow. It could be done concurrently\nfrom the client side, but IPinfo supports a batch endpoint to allow you to\ngroup together IPs and let us handle retrieving details for them in bulk for\nyou.\n\n```python\n\u003e\u003e\u003e import ipinfo, pprint\n\u003e\u003e\u003e access_token = '123456789abc'\n\u003e\u003e\u003e handler = ipinfo.getHandler(access_token)\n\u003e\u003e\u003e pprint.pprint(handler.getBatchDetails([\n...   '1.1.1.1',\n...   '8.8.8.8',\n...   '1.2.3.4/country',\n... ]))\n{'1.1.1.1': {'city': '',\n             'country': 'AU',\n             'country_name': 'Australia',\n             'hostname': 'one.one.one.one',\n             'ip': '1.1.1.1',\n             'latitude': '-33.4940',\n             'loc': '-33.4940,143.2100',\n             'longitude': '143.2100',\n             'org': 'AS13335 Cloudflare, Inc.',\n             'region': ''},\n '1.2.3.4/country': 'US',\n '8.8.8.8': {'city': 'Mountain View',\n             'country': 'US',\n             'country_name': 'United States',\n             'hostname': 'dns.google',\n             'ip': '8.8.8.8',\n             'latitude': '37.3860',\n             'loc': '37.3860,-122.0838',\n             'longitude': '-122.0838',\n             'org': 'AS15169 Google LLC',\n             'postal': '94035',\n             'region': 'California',\n             'timezone': 'America/Los_Angeles'}}\n```\n\nThe input size is not limited, as the interface will chunk operations for you\nbehind the scenes.\n\nPlease see [the official documentation](https://ipinfo.io/developers/batch) for\nmore information and limitations.\n\n## Other Libraries\n\nThere are official [IPinfo client libraries](https://ipinfo.io/developers/libraries) available for many languages including PHP, Go, Java, Ruby, and many popular frameworks such as Django, Rails, and Laravel. There are also many third-party libraries and integrations available for our API.\n\n## About IPinfo\n\nFounded in 2013, IPinfo prides itself on being the most reliable, accurate, and in-depth source of IP address data available anywhere. We process terabytes of data to produce our custom IP geolocation, company, carrier, VPN detection, hosted domains, and IP type data sets. Our API handles over 40 billion requests a month for 100,000 businesses and developers.\n\n[![image](https://avatars3.githubusercontent.com/u/15721521?s=128\u0026u=7bb7dde5c4991335fb234e68a30971944abc6bf3\u0026v=4)](https://ipinfo.io/)\n","funding_links":[],"categories":["Python"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fipinfo%2Fpython","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fipinfo%2Fpython","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fipinfo%2Fpython/lists"}