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.country_name)
print("Country Code:", client.country_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
jsonorhtmlformat by setting theuse_formatproperty 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hostip_client-1.0.4.tar.gz.
File metadata
- Download URL: hostip_client-1.0.4.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cf45b12576fae7148bbd5aa68fa91a628b45e93ee946daba20f3ea78e8136e1a
|
|
| MD5 |
ae83d78e5e77e180badfb82cef78c7fd
|
|
| BLAKE2b-256 |
f707ab4d3ba37ff0321fca624e2cc9e6645947116d59a4773f585d9658b4e305
|
Provenance
The following attestation bundles were made for hostip_client-1.0.4.tar.gz:
Publisher:
python-publish.yml on rh363/hostip_client
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hostip_client-1.0.4.tar.gz -
Subject digest:
cf45b12576fae7148bbd5aa68fa91a628b45e93ee946daba20f3ea78e8136e1a - Sigstore transparency entry: 152371453
- Sigstore integration time:
-
Permalink:
rh363/hostip_client@5e831d6b7a4c11edabd3ca5fd73667cb5c9dd1f2 -
Branch / Tag:
refs/tags/1.0.4 - Owner: https://github.com/rh363
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@5e831d6b7a4c11edabd3ca5fd73667cb5c9dd1f2 -
Trigger Event:
release
-
Statement type:
File details
Details for the file hostip_client-1.0.4-py3-none-any.whl.
File metadata
- Download URL: hostip_client-1.0.4-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b6134f1253e7b1c7f3a1933b1320288d1afe22f4ffd5557b64f0abbff5cbadb6
|
|
| MD5 |
b0fb492ed6cacabf39b23a393e5d4d83
|
|
| BLAKE2b-256 |
625da50064e774ff009dab017ea878baf36cc55824bdc88ee1a758b88aa06713
|
Provenance
The following attestation bundles were made for hostip_client-1.0.4-py3-none-any.whl:
Publisher:
python-publish.yml on rh363/hostip_client
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hostip_client-1.0.4-py3-none-any.whl -
Subject digest:
b6134f1253e7b1c7f3a1933b1320288d1afe22f4ffd5557b64f0abbff5cbadb6 - Sigstore transparency entry: 152371455
- Sigstore integration time:
-
Permalink:
rh363/hostip_client@5e831d6b7a4c11edabd3ca5fd73667cb5c9dd1f2 -
Branch / Tag:
refs/tags/1.0.4 - Owner: https://github.com/rh363
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@5e831d6b7a4c11edabd3ca5fd73667cb5c9dd1f2 -
Trigger Event:
release
-
Statement type: