Official Python SDK for weatherxu.com
Project description
WeatherXu Python SDK
Official Python SDK for accessing WeatherXu's weather data API.
Installation
From PyPI
pip install weatherxu
From Source
git clone https://github.com/weatherxu/weatherxu-python.git
cd weatherxu-python
pip install -r requirements.txt
pip install -e .
Quick Start
from weatherxu import WeatherXu
# Initialize the client
client = WeatherXu(api_key="YOUR_API_KEY", units="metric")
# Get current weather and forecast for New York City
weather = client.get_weather(
lat=40.7128,
lon=-74.0060,
parts=['currently', 'hourly', 'daily']
)
# Print current temperature
print(f"Current temperature: {weather.currently.temperature}°C")
# Get hourly forecasts
for hour in weather.hourly:
print(f"Time: {hour.forecast_start}, Temperature: {hour.temperature}°C")
# Get historical weather data
from datetime import datetime, timedelta
end_time = int(datetime.now().timestamp())
start_time = int((datetime.now() - timedelta(days=1)).timestamp())
historical = client.get_historical(
lat=40.7128,
lon=-74.0060,
start=start_time,
end=end_time
)
# Print historical data
for record in historical.hourly:
print(f"Time: {record.forecast_start}, Temperature: {record.temperature}°C")
Features
- Type hints and dataclasses for better IDE support
- Automatic parsing of timestamps to datetime objects
- Comprehensive error handling
- Support for both metric and imperial units
- Optional request timeout configuration
API Reference
Initialization
WeatherXu(
api_key: str,
units: str = 'metric',
timeout: int = 10
)
Methods
get_weather()
Get current weather and forecast data for a location.
get_weather(
lat: float,
lon: float,
parts: Optional[List[str]] = None,
units: Optional[str] = None
) -> WeatherData
Parameters:
lat: Latitude (-90 to 90)lon: Longitude (-180 to 180)parts: Optional list of data blocks to include ('alerts', 'currently', 'hourly', 'daily')units: Optional unit system ('metric' or 'imperial')
get_historical()
Get historical weather data for a location.
get_historical(
lat: float,
lon: float,
start: int,
end: int,
units: Optional[str] = None
) -> HistoricalData
Parameters:
lat: Latitude (-90 to 90)lon: Longitude (-180 to 180)start: Start time (Unix timestamp)end: End time (Unix timestamp)units: Optional unit system ('metric' or 'imperial')
Error Handling
The SDK throws WeatherError for any API or network-related errors. Each error includes:
- Error message
- HTTP status code (when available)
- Error code (when provided by the API)
try:
weather = client.get_weather(lat=40.7128, lon=-74.0060)
except WeatherError as e:
print(f"Error: {e}")
if e.status_code:
print(f"Status code: {e.status_code}")
Development
Installation
For development, you can install all development dependencies using:
pip install -r requirements-dev.txt
This includes:
- Testing tools (pytest, pytest-cov)
- Code formatting (black, isort)
- Type checking (mypy)
- Documentation (Sphinx)
- Code quality (flake8, pylint)
Requirements
- Python 3.7 or higher
- requests library
Project details
Release history Release notifications | RSS feed
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 weatherxu-1.0.1.tar.gz.
File metadata
- Download URL: weatherxu-1.0.1.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
90cc20a0c36ac6e084dba8ff0e07bbe4ce5abb04a9e941427d146eff496359e0
|
|
| MD5 |
c6a93a7e364b96e563caa87a356bb536
|
|
| BLAKE2b-256 |
39231d5069a72e682ebeeda017914366367502850edff862ae70815e74eeaef8
|
File details
Details for the file weatherxu-1.0.1-py3-none-any.whl.
File metadata
- Download URL: weatherxu-1.0.1-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c946af0808a320951933a2b7f888e1566c6766e53acd78f0401c94a15005dbfd
|
|
| MD5 |
5b8fa70a2c081a6f037f60d8480cf00f
|
|
| BLAKE2b-256 |
6f4c87d21552b75af1b4c0d65ac8112ea78175794c110a27c5d0f342fcea7141
|