weatherxu


Nameweatherxu JSON
Version 1.0.1 PyPI version JSON
download
home_pagehttps://github.com/weatherxu/weatherxu-python
SummaryOfficial Python SDK for weatherxu.com
upload_time2025-01-29 20:34:01
maintainerNone
docs_urlNone
authorWeatherXu
requires_pythonNone
licenseNone
keywords weather weather data weather forecast weather api
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # WeatherXu Python SDK

Official Python SDK for accessing WeatherXu's weather data API.

## Installation

### From PyPI
```bash
pip install weatherxu
```

### From Source
```bash
git clone https://github.com/weatherxu/weatherxu-python.git
cd weatherxu-python
pip install -r requirements.txt
pip install -e .
```

## Quick Start

```python
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

```python
WeatherXu(
    api_key: str,
    units: str = 'metric',
    timeout: int = 10
)
```

### Methods

#### get_weather()

Get current weather and forecast data for a location.

```python
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.

```python
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)

```python
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:

```bash
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

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/weatherxu/weatherxu-python",
    "name": "weatherxu",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "weather, weather data, weather forecast, weather api",
    "author": "WeatherXu",
    "author_email": "contact@weatherxu.com",
    "download_url": "https://files.pythonhosted.org/packages/39/23/1d5069a72e682ebeeda017914366367502850edff862ae70815e74eeaef8/weatherxu-1.0.1.tar.gz",
    "platform": null,
    "description": "# WeatherXu Python SDK\n\nOfficial Python SDK for accessing WeatherXu's weather data API.\n\n## Installation\n\n### From PyPI\n```bash\npip install weatherxu\n```\n\n### From Source\n```bash\ngit clone https://github.com/weatherxu/weatherxu-python.git\ncd weatherxu-python\npip install -r requirements.txt\npip install -e .\n```\n\n## Quick Start\n\n```python\nfrom weatherxu import WeatherXu\n\n# Initialize the client\nclient = WeatherXu(api_key=\"YOUR_API_KEY\", units=\"metric\")\n\n# Get current weather and forecast for New York City\nweather = client.get_weather(\n    lat=40.7128,\n    lon=-74.0060,\n    parts=['currently', 'hourly', 'daily']\n)\n\n# Print current temperature\nprint(f\"Current temperature: {weather.currently.temperature}\u00b0C\")\n\n# Get hourly forecasts\nfor hour in weather.hourly:\n    print(f\"Time: {hour.forecast_start}, Temperature: {hour.temperature}\u00b0C\")\n\n# Get historical weather data\nfrom datetime import datetime, timedelta\n\nend_time = int(datetime.now().timestamp())\nstart_time = int((datetime.now() - timedelta(days=1)).timestamp())\n\nhistorical = client.get_historical(\n    lat=40.7128,\n    lon=-74.0060,\n    start=start_time,\n    end=end_time\n)\n\n# Print historical data\nfor record in historical.hourly:\n    print(f\"Time: {record.forecast_start}, Temperature: {record.temperature}\u00b0C\")\n```\n\n## Features\n\n- Type hints and dataclasses for better IDE support\n- Automatic parsing of timestamps to datetime objects\n- Comprehensive error handling\n- Support for both metric and imperial units\n- Optional request timeout configuration\n\n## API Reference\n\n### Initialization\n\n```python\nWeatherXu(\n    api_key: str,\n    units: str = 'metric',\n    timeout: int = 10\n)\n```\n\n### Methods\n\n#### get_weather()\n\nGet current weather and forecast data for a location.\n\n```python\nget_weather(\n    lat: float,\n    lon: float,\n    parts: Optional[List[str]] = None,\n    units: Optional[str] = None\n) -> WeatherData\n```\n\nParameters:\n- `lat`: Latitude (-90 to 90)\n- `lon`: Longitude (-180 to 180)\n- `parts`: Optional list of data blocks to include ('alerts', 'currently', 'hourly', 'daily')\n- `units`: Optional unit system ('metric' or 'imperial')\n\n#### get_historical()\n\nGet historical weather data for a location.\n\n```python\nget_historical(\n    lat: float,\n    lon: float,\n    start: int,\n    end: int,\n    units: Optional[str] = None\n) -> HistoricalData\n```\n\nParameters:\n- `lat`: Latitude (-90 to 90)\n- `lon`: Longitude (-180 to 180)\n- `start`: Start time (Unix timestamp)\n- `end`: End time (Unix timestamp)\n- `units`: Optional unit system ('metric' or 'imperial')\n\n## Error Handling\n\nThe SDK throws `WeatherError` for any API or network-related errors. Each error includes:\n- Error message\n- HTTP status code (when available)\n- Error code (when provided by the API)\n\n```python\ntry:\n    weather = client.get_weather(lat=40.7128, lon=-74.0060)\nexcept WeatherError as e:\n    print(f\"Error: {e}\")\n    if e.status_code:\n        print(f\"Status code: {e.status_code}\")\n```\n\n## Development\n\n### Installation\n\nFor development, you can install all development dependencies using:\n\n```bash\npip install -r requirements-dev.txt\n```\n\nThis includes:\n- Testing tools (pytest, pytest-cov)\n- Code formatting (black, isort)\n- Type checking (mypy)\n- Documentation (Sphinx)\n- Code quality (flake8, pylint)\n\n## Requirements\n\n- Python 3.7 or higher\n- requests library\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Official Python SDK for weatherxu.com",
    "version": "1.0.1",
    "project_urls": {
        "Homepage": "https://github.com/weatherxu/weatherxu-python"
    },
    "split_keywords": [
        "weather",
        " weather data",
        " weather forecast",
        " weather api"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "6f4c87d21552b75af1b4c0d65ac8112ea78175794c110a27c5d0f342fcea7141",
                "md5": "5b8fa70a2c081a6f037f60d8480cf00f",
                "sha256": "c946af0808a320951933a2b7f888e1566c6766e53acd78f0401c94a15005dbfd"
            },
            "downloads": -1,
            "filename": "weatherxu-1.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5b8fa70a2c081a6f037f60d8480cf00f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 5777,
            "upload_time": "2025-01-29T20:33:59",
            "upload_time_iso_8601": "2025-01-29T20:33:59.881911Z",
            "url": "https://files.pythonhosted.org/packages/6f/4c/87d21552b75af1b4c0d65ac8112ea78175794c110a27c5d0f342fcea7141/weatherxu-1.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "39231d5069a72e682ebeeda017914366367502850edff862ae70815e74eeaef8",
                "md5": "c6a93a7e364b96e563caa87a356bb536",
                "sha256": "90cc20a0c36ac6e084dba8ff0e07bbe4ce5abb04a9e941427d146eff496359e0"
            },
            "downloads": -1,
            "filename": "weatherxu-1.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "c6a93a7e364b96e563caa87a356bb536",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 5956,
            "upload_time": "2025-01-29T20:34:01",
            "upload_time_iso_8601": "2025-01-29T20:34:01.093266Z",
            "url": "https://files.pythonhosted.org/packages/39/23/1d5069a72e682ebeeda017914366367502850edff862ae70815e74eeaef8/weatherxu-1.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-01-29 20:34:01",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "weatherxu",
    "github_project": "weatherxu-python",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "weatherxu"
}
        
Elapsed time: 0.62021s