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.5.tar.gz (79.2 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.5-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: astra_client-0.1.5.tar.gz
  • Upload date:
  • Size: 79.2 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.5.tar.gz
Algorithm Hash digest
SHA256 c43a676d50aa4709a4c9d4341be5c6459c05cbadf249186ea90eb509fb252a3e
MD5 4322d2e2704476fea07d1dfa03874e67
BLAKE2b-256 9cfa674e4f18bfa24e14b9de7acfe010773261c38a5bf9b09cfdc7f28b5f4b0a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: astra_client-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 12.1 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.5-py3-none-any.whl
Algorithm Hash digest
SHA256 7a6deead98461c517b1d4b365bd8f46a9e853060789034e754babf22f855968d
MD5 3e87869604cae7bd442ec4cbcee1ab5a
BLAKE2b-256 12050a2458e9e4e829fc5c1b772b530369e01d18f96dc30a6776d29e8706e3a6

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