Skip to main content

A small hostip API client

Project description

GeoIP Client Package

This package provides a client for accessing geographic information about an IP address using the hostip.info API. It validates IP addresses and URLs, and handles JSON and HTML response formats.

Features

  • Validate IPv4 addresses and service URLs.
  • Retrieve geographic information such as country name, country code, city, latitude, and longitude using hostip.info API.
  • Handle responses in both JSON and HTML formats.

Installation

To install the package, clone the repository and install the necessary dependencies:

pip install hostip_client

Usage

Import the Client

from hostip_client.client import Client

Create a Client Instance

To create an instance of the Client, provide a valid IP address, service URL, and an optional format (either 'json' or 'html').

ip_address = "8.8.8.8"  # Replace with a valid IP address
client = Client(ip_address=ip_address)

Handling Exceptions

  • InvalidIpAddress: Raised when the provided IP address is not in a valid format.
  • InvalidServiceUrl: Raised when the service URL is not valid.
  • InvalidFormat: Raised if the format is not 'json' or 'html'.

Accessing Geographic Information

Once a Client instance is created, access the geographic information like so:

print("Country Name:", client.contry_name)
print("Country Code:", client.contry_code)
print("City:", client.city)
print("Latitude:", client.latitude)
print("Longitude:", client.longitude)

Configuration

  • Service URL: You can specify a different hostip.info service endpoint by passing a custom URL to hostip_url.
  • Format: Choose either json or html format by setting the use_format property during initialization.

License

This project is licensed under the MIT License.

Contributing

Contributions are welcome! Please submit a pull request or open an issue to discuss further.

Acknowledgments

This package uses the hostip.info API for geographic data.

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

hostip_client-1.0.0.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

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

hostip_client-1.0.0-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: hostip_client-1.0.0.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.13.0

File hashes

Hashes for hostip_client-1.0.0.tar.gz
Algorithm Hash digest
SHA256 97e7d10ed56d7cf3198cc0ad79c57e4ed35746618d14f235ae00231020afe9bc
MD5 f4ffbe21e44b421758749d251dbb90f0
BLAKE2b-256 427f63d724ae1f3a1f47eda58ef7f8c50f6d957c79a5f1bc3a59b5b61878ec61

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hostip_client-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.13.0

File hashes

Hashes for hostip_client-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3ed8e228150f5918fe5e360fe8a2d4d72071716f64125bb480f6c533d0a8b96d
MD5 04809ed77da401d194114b169f2ad6ea
BLAKE2b-256 230514cd7d81864f8d4e6cef1f4fa8078b051940bd82782901526a52c492e7c6

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