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.2.tar.gz (37.4 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.2-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: astra_client-0.1.2.tar.gz
  • Upload date:
  • Size: 37.4 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.2.tar.gz
Algorithm Hash digest
SHA256 fafc6049b46079f456b543aeea55b2d7b43b24c3adb3568950d4676e0c75e4ac
MD5 3aa7f1a22e8f48f79c845537711e02f7
BLAKE2b-256 7871165682acc2a993b008eb686496d967c8ef66be6df2c58a480aef9a3fbb34

See more details on using hashes here.

File details

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

File metadata

  • Download URL: astra_client-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 10.0 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9465717d8a28c4c469306426000e4d37e58f8bdbddc0c62ca71f4c8a75b909be
MD5 24d9d4841478bce87f64f099e2b51aeb
BLAKE2b-256 1953e1025ee5a201a7eda5f61c7b9c1b5610ede3d34219dafc570a57c3caf9bb

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