Skip to main content

Async HTTP client with clean API and automatic error handling

Project description

astra-client

Async HTTP client for Python with clean API and automatic error handling

PyPI version Python License: MIT CI


Key Features

  • Zero-boilerplate URLs — write "google.com" instead of "https://google.com"
  • Automatic error handling — 4xx/5xx responses raise typed exceptions, no manual checks needed
  • Async context managers — clean resource lifecycle with async with
  • Full HTTP verb coverage — GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS
  • Typed exception hierarchy — catch exactly what you need, from NotFoundError to AstraHttpError
  • Python 3.10+ — modern type hints throughout (X | None, dict[str, Any])

Installation

pip install astra-client
uv add astra-client

Quick Start

import asyncio
import astra

async def main():
    async with astra.ClientSession() as session:
        async with session.get("httpbin.org/get") as response:
            print(response.status)
            data = await response.json()
            print(data)

asyncio.run(main())

No scheme? No problem. astra-client automatically prepends https:// if missing.

POST with JSON

async with astra.ClientSession() as session:
    async with session.post(
        "httpbin.org/post",
        json={"name": "astra", "fast": True},
    ) as response:
        print(await response.json())

Custom headers & base URL

async with astra.ClientSession(
    base_url="https://api.example.com",
    headers={"Authorization": "Bearer TOKEN"},
    timeout=10.0,
) as session:
    async with session.get("/users/me") as response:
        user = await response.json()

Error Handling

astra-client raises typed exceptions automatically — no need to call raise_for_status() manually.

import astra

async def fetch():
    try:
        async with astra.ClientSession() as session:
            async with session.get("httpbin.org/status/404") as response:
                ...
    except astra.NotFoundError:
        print("Resource not found")
    except astra.UnauthorizedError:
        print("Invalid credentials")
    except astra.TooManyRequestsError:
        print("Rate limit hit — slow down")
    except astra.TimeoutError:
        print("Request timed out")
    except astra.ConnectionError:
        print("Could not reach the server")
    except astra.AstraHttpError as e:
        print(f"Unexpected error: {e}")

Exception Hierarchy

AstraHttpError
├── NetworkError
│   ├── ConnectionError
│   ├── TimeoutError
│   ├── TooManyRedirectsError
│   └── InvalidURLError
└── HTTPStatusError
    ├── ClientError          (4xx)
    │   ├── BadRequestError          400
    │   ├── UnauthorizedError        401
    │   ├── ForbiddenError           403
    │   ├── NotFoundError            404
    │   ├── MethodNotAllowedError    405
    │   ├── UnprocessableEntityError 422
    │   └── TooManyRequestsError     429
    └── ServerError          (5xx)
        ├── InternalServerError      500
        ├── BadGatewayError          502
        ├── ServiceUnavailableError  503
        └── GatewayTimeoutError      504

Response API

async with session.get("httpbin.org/json") as response:
    response.status        # int — HTTP status code
    response.headers       # httpx.Headers

    text = await response.text()   # str
    data = await response.json()   # Any
    raw  = await response.read()   # bytes

Requirements

  • Python 3.10+
  • httpx >= 0.28.1

License

astra-client is released under the MIT License.

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

astra_client-0.1.0.tar.gz (12.3 kB view details)

Uploaded Source

Built Distribution

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

astra_client-0.1.0-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file astra_client-0.1.0.tar.gz.

File metadata

  • Download URL: astra_client-0.1.0.tar.gz
  • Upload date:
  • Size: 12.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for astra_client-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5d20078ba7c8ee27068a145c9ab2f0572e61c1d735c81720ea86d047e0abeb00
MD5 5af1e9c5b7188614651a4c3a44330996
BLAKE2b-256 4ec17917442073bddeda8c44714091ad8311edb4c2eb6f82aa871cf6abb8a37e

See more details on using hashes here.

File details

Details for the file astra_client-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: astra_client-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for astra_client-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 689b66c797636e28bfe38d24e0415dbb75586a310a6b3607866ff3acc32a6b75
MD5 4a599ca37995c3bba9a1c08dae5f54d1
BLAKE2b-256 4f3b1fb22db9e367bdcd05fdef57ebc1e26acc5b7ffbb24078c6ee6cda42f496

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