Skip to main content

FreeGeoIp's RESTful API client for Python

Project description

Description

Simple Python library made for consuming FreeGeoIp's RESTful API. API returns geo location data either for the current IP address that made the request or for the provided IP address.

Installing and usage

Install using pip (available at pypi - freegeoip-client)

pip install freegeoip-client

Use it in code

from freegeoip_client import FreeGeoIpClient

client = FreeGeoIpClient(api_key="some_api_key")

geo_data = client.get_geo_location()
geo_data_by_ip = client.get_geo_location_for_ip_address("8.8.8.8")

Example output

>>> from freegeoip_client import FreeGeoIpClient
>>> client = FreeGeoIpClient(api_key="some_api_key")
>>> client.get_geo_location_for_ip_address("8.8.8.8")
{'ip': '8.8.8.8', 'country_code': 'US', 'country_name': 'United States', 'region_code': '', 'region_name': '', 'city': '', 'zip_code': '', 'time_zone': 'America/Chicago', 'latitude': 37.751, 'longitude': -97.822, 'metro_code': 0}

Building project locally

Using pip - Package Installer for Python and setup.py, __init__.py files to define which modules will be included in a package, project can be built and installed locally in order to import it in another Python script.

# OS-level (/usr/local/lib/<python version>)
python -m pip install -e .

# for current user (/home/<user>)
python -m pip install --user -e .

# virtual environment (wherever virtual environment is initialized)
python -m venv env
source /env/bin/activate
python -m pip install -e .

Importing in different script(s):

from freegeoip_client import FreeGeoIpClient

Third party dependencies for project development

Required:

  • requests - Required to make HTTP requests

Not required (but highly encouraged to improve code quality):

  • flake8 - Tool to enforce style guide for Python code (PEP8)
  • black - tool to format Python code
  • pytest - framework for writing small and readable tests
  • requests-mock - library at its core is simply a transport adapter that can be preloaded with responses that are returned if certain URIs are requested

Dependencies are defined in requirements.txt file and are installed using pip. Dependencies can be installed on OS-level, for current user or within virtual environments.

# OS-level (/usr/local/lib/<python version>)
python -m pip install -r requirements.txt

# for current user (/home/<user>)
python -m pip install --user -r requirements.txt

# virtual environment (wherever virtual environment is initialized)
python -m venv env
source /env/bin/activate
python -m pip install -r requirements.txt

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

freegeoip-client-1.0.4.tar.gz (4.6 kB view details)

Uploaded Source

File details

Details for the file freegeoip-client-1.0.4.tar.gz.

File metadata

  • Download URL: freegeoip-client-1.0.4.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for freegeoip-client-1.0.4.tar.gz
Algorithm Hash digest
SHA256 efe3cda419efc6dae6c4455e04d876f93665faea1320b47b6caafbf55b9929f6
MD5 0566d3b61d8487fe3961fd6ad5ba6464
BLAKE2b-256 aaa497ec558e3d92f243d578165c21d9b09d03dd2b56f6b52a24914f09c0bfd3

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