Welcome to AioGeoIP

AioGeoIP is a library for geolocation by IPv4 address that uses the IP-API platform completely free of charge and provides support for parallelism with asyncio and synchronized methods with Requests and urllib3, in addition to additional features for optimizing your software.

Current version is 0.1.1

Key Features

  • Support for asynchronous requests with aiohttp.

  • Synchronous backend in urllib and requests.

  • Cached requests for greater optimization.

Library Installation

$ pip install aiogeoip

Getting Started

aiogeoip:

import socket
import asyncio
from aiogeoip import AioGeoIP

async def main(aio):
   ip = socket.gethostbyname('www.google.com')
   print(await aio.geoip(ip))

aio = AioGeoIP()
asyncio.get_event_loop().run_until_complete(main(aio))

OR

import pprint
import socket
import asyncio
from aiogeoip import geoip

async def main():
   ip = socket.gethostbyname('www.google.com')
   pprint.pprint(await geoip(ip))

asyncio.get_event_loop().run_until_complete(main())

urllib geoip:

import socket
from aiogeoip import (requests_geoip as geoip)

ip = socket.gethostbyname('www.google.com')
print(geoip(ip))

requests geoip:

import socket
from aiogeoip import (urllib_geoip as geoip)

ip = socket.gethostbyname('www.google.com')
print(geoip(ip))

Response as dict:

{ 'as': 'AS61592 FORT LINK INTERNET'
      'CORPORATIVA BRASIL LTDA'
      'EPP',
 'city': 'Camaragibe',
 'continent': 'South America',
 'continentCode': 'SA',
 'country': 'Brazil',
 'countryCode': 'BR',
 'district': '',
 'hosting': False,
 'isp': 'FORT LINK INTERNET '
     'CORPORATIVA BRASIL LTDA EPP',
 'lat': -7.9878,
 'lon': -34.9914,
 'org': 'FORT LINK INTERNET '
     'CORPORATIVA BRASIL LTDA'
     'EPP',
 'query': '45.234.102.103',
 'region': 'PE',
 'regionName': 'Pernambuco',
 'reverse': 'fort2-103.fortlink.net.br',
 'status': 'success',
 'timezone': 'America/Recife',
 'zip': '54750'}

Source code

The project is hosted on GitHub

Please feel free to file an issue on the bug tracker if you have found a bug or have some suggestion in order to improve the library.

Dependencies

  • Python 3.6+

  • aiohttp

  • requests

Contributing

Please read the instructions for contributors.

Authors and License

The aiogeoip package is written mostly by Paulo Júnior.

It’s Apache 2 licensed and freely available.

Feel free to improve this package and send a pull request to GitHub.

Table Of Contents