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.3.tar.gz (47.5 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.3-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: astra_client-0.1.3.tar.gz
  • Upload date:
  • Size: 47.5 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.3.tar.gz
Algorithm Hash digest
SHA256 ce42c064a89b91a64774b16846ae55c9dced8481456c1bd031354b3d8bb3dd47
MD5 4440ca004ff008e1da9b5155dd19090a
BLAKE2b-256 d724d57f7b198dcc7057640cf4ef5eff1fbc5a47cc1c6049101a082908b7438f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: astra_client-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 10.2 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ef4f658d24d29f7e66a6a3d1cca2493918d9b2bb96c1e52cddfb7edbaed1495b
MD5 f269a6505622d76b135179706fd18fa7
BLAKE2b-256 8714be811fc88f02611b8fa404ca1ce06c88334edada62a458404634f819d1a3

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