The Python client for the RandomCoords API to fetch random geographic coordinates worldwide.
pip install randomcoords- Python 3.8 or higher.
- A RandomCoords API token.
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)| Key | Type | Default | Description |
|---|---|---|---|
api_token |
str |
— | Required. Your API token. |
base_url |
str |
https://api.randomcoords.com/v1/ |
API base URL. |
timeout |
float |
5.0 |
Request timeout in seconds. |
None
Metadata and a list of supported regions.
None
Metadata and a list of supported countries.
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).
Metadata and random coordinates within the specified region.
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).
Metadata and random coordinates within the specified country.
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)All response and error types are available as top-level imports:
from randomcoords import (
RegionsResponse,
CountriesResponse,
RegionCoordinatesResponse,
CountryCoordinatesResponse,
RandomCoordsApiError,
)If you encounter a bug, please open an issue.
MIT © Talha Awan