Skip to main content

The Python client for the RandomCoords API to fetch random geographic coordinates worldwide.

Project description

RandomCoords Python Client

PyPI version CI Supported Python Versions Ruff mypy License: MIT Downloads

The Python client for the RandomCoords API to fetch random geographic coordinates worldwide.

Installation

pip install randomcoords

Requirements

Usage

from randomcoords import RandomCoords

client = RandomCoords({"api_token": "your-api-token"})

# Get random coordinates from the United States
coords = client.get_country_coordinates("united-states", {"limit": 10})
print(coords)

Available Methods

get_regions()

Parameters

None

Returns (RegionsResponse)

Metadata and a list of supported regions.

get_countries()

Parameters

None

Returns (CountriesResponse)

Metadata and a list of supported countries.

get_region_coordinates(region, options)

Parameters

  • region (str) – The region identifier (e.g., "world", "europe").
  • options (dict, optional):
    • limit (int, optional) – Maximum number of coordinates to return (default: 1, maximum: 100).

Returns (RegionCoordinatesResponse)

Metadata and random coordinates within the specified region.

get_country_coordinates(country, options)

Parameters

  • country (str) – The country identifier (e.g., "united-states", "australia").
  • options (dict, optional):
    • limit (int, optional) – Maximum number of coordinates to return (default: 1, maximum: 100).

Returns (CountryCoordinatesResponse)

Metadata and random coordinates within the specified country.

Error Handling

The library throws:

  • ValueError – for validation or unexpected usage issues (e.g., invalid inputs).
  • RandomCoordsApiError – for HTTP/API-related failures. This custom error includes:
    • statusCode: HTTP status code (e.g., 401, 404, 429).
    • url: The API request URL.
    • message: A descriptive error message.

Example:

from randomcoords import RandomCoordsApiError

try:
    # a method call
except ValueError as ve:
    print("Input error:", ve)
except RandomCoordsApiError as api_err:
    print(f"API error {api_err.status_code} at {api_err.url}: {api_err.message}")
except Exception as e:
    print("Unexpected error:", e)

Typed Responses and Exceptions

All response and error types are available as top-level imports:

from randomcoords import (
    RegionsResponse,
    CountriesResponse,
    RegionCoordinatesResponse,
    CountryCoordinatesResponse,
    RandomCoordsApiError,
)

API Reference

Issues

If you encounter a bug, please open an issue.

License

MIT © Talha Awan

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

randomcoords-1.0.4.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

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

randomcoords-1.0.4-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file randomcoords-1.0.4.tar.gz.

File metadata

  • Download URL: randomcoords-1.0.4.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for randomcoords-1.0.4.tar.gz
Algorithm Hash digest
SHA256 f1db65bf033f1151e6a8ac5acedaa9da549ca035f5a23cf517e3cea164375429
MD5 961005bee1c58419632c8f924f0dc9fd
BLAKE2b-256 bc0c831a00430c1b45f24e29a471d81b7db15ee485a372b5f8a1887acb7101c5

See more details on using hashes here.

File details

Details for the file randomcoords-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: randomcoords-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for randomcoords-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 f2b76067b7a7ae01d037be6911407947e95ef47095ce33bbb374e3e4b7f36cea
MD5 4741a2cb6da7c6c1285b070206233d8c
BLAKE2b-256 b66efddbb86378ae5993a3bdb9786e6e44ba9e81ccabe054f4e2ba07dd49e348

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