Skip to main content

allure-api-client

A lightweight API client built on top of httpx that adds convenient defaults for testing, plus optional Allure-friendly request/response logging. It ships with:

  • Synchronous and asynchronous clients
  • Optional Allure hooks to log cURL, request, and response details
  • Simple Bearer token authentication helper
  • Built-in status code verification in a single send_request call

Requirements

  • Python 3.11+

Installation

pip install allure-api-client

If you want Allure reporting, also install Allure and its pytest plugin and generate a report when you run tests:

Example test run with Allure report generation:

pytest --alluredir=./allure-results
allure serve ./allure-results

Quick start (synchronous)

from api_client import APIClient, BearerToken

client = APIClient(
    base_url="https://api.example.com",
    auth=BearerToken("YOUR_ACCESS_TOKEN"),  # optional
    verify=False,                            # optional, default False
    with_allure=True,                        # optional, default True: attach cURL/response to Allure
    with_print=False,                        # optional, default False: print cURL/response
    with_logger=False                        # optional, default False: log cURL/response
)

response = client.send_request(
    method="GET",
    path="/users",
    params={"page": 1},
    # By default, the client expects HTTP 200 (HTTPStatus.OK)
    # You can override the expectation per request:
    # status_code=201,
)
print(response.status_code)
print(response.json())

Quick start (asynchronous)

import asyncio
from api_client import AsyncAPIClient, BearerToken

async def main() -> None:
    async with AsyncAPIClient(
        base_url="https://api.example.com",
        auth=BearerToken("YOUR_ACCESS_TOKEN"),  # optional
        verify=False,                            # optional
        with_allure=True,                        # optional
        with_print=False,                        # optional
        with_logger=False                        # optional
    ) as client:
        response = await client.send_request(
            method="GET",
            path="/users",
        )
        print(response.status_code)
        print(response.json())

asyncio.run(main())

Authentication

Use a Bearer token if your API requires it:

from api_client import BearerToken

auth = BearerToken("YOUR_ACCESS_TOKEN")
# pass it to APIClient/AsyncAPIClient via the auth parameter

Allure integration

  • By default, the clients are created with with_allure=True. The library will attach helpful request/response data to Allure, including a cURL snippet for easy reproduction.
  • If you do not use Allure, set with_allure=False.
  • Hooks can output the same cURL and response payload through print, logger, Allure attachments, or any combination of them with with_print, with_logger, and with_allure.

Status code handling

  • send_request verifies the response status code for you using the status_code parameter (default: 200 OK).
  • If the actual status code does not match the expected value, an assertion-like error is raised coming from the underlying check.

Example expecting 201 Created:

from api_client import APIClient

client = APIClient(base_url="https://api.example.com")
response = client.send_request(
    method="POST",
    path="/users",
    json={"name": "Alice"},
    status_code=201,
)

Configuration reference

Common parameters on client initialization:

  • base_url: Base URL string for your API (e.g., https://api.example.com)
  • auth: Any httpx-compatible auth object; BearerToken helper is provided
  • cookies: Optional httpx.Cookies to send on each request
  • verify: Whether to verify TLS certificates (default False)
  • with_allure: Enable/disable Allure hooks (default True)
  • with_print: Enable/disable print hooks for cURL and response output (default False)
  • with_logger: Enable/disable logger hooks for cURL and response output (default False)

Common parameters on send_request:

  • method: HTTP method (e.g., "GET", "POST", ...)
  • path: Path appended to base_url
  • headers, params, data, json, files
  • follow_redirects (default True)
  • timeout (seconds, default 300)
  • status_code: expected response status (default 200)

Contributing

Contributions are welcome! Please open an issue or a pull request.

License

Released under the MIT License. See LICENSE.

Release files for allure-api-client 26.208

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for allure-api-client 26.208
File Size Uploaded
allure_api_client-26.208.tar.gz 7.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for allure-api-client 26.208
File Interpreter ABI Platform
allure_api_client-26.208-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 17.9 kB

Release files / allure_api_client-26.208.tar.gz

Download URL allure_api_client-26.208.tar.gz
Size 7.2 kB
Tags Source
SHA-256 checksum
How to use checksums
f78cf63533b8fdb66a57cb84e56e25181201e3bca4ddcb6dc98166918db87238
BLAKE2b-256 checksum
How to use checksums
3790617db47fe801626672fbd627b57161503ae2574f9c65a16e4b0d101f96fd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.1 CPython/3.14.6 Linux/6.17.0-1020-azure

Release files / allure_api_client-26.208-py2.py3-none-any.whl

Download URL allure_api_client-26.208-py2.py3-none-any.whl
Size 10.6 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
ec8a85c94295bc096094defcfc0a80e91909d8f5659836c1d0b33e9c040910ca
BLAKE2b-256 checksum
How to use checksums
57123f62ff656e93d1ef5a2a6e0385fbd5d9510fb0c62ac602843a50bbc46ae1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.1 CPython/3.14.6 Linux/6.17.0-1020-azure

Release history Release notifications | RSS feed

This release

26.208 This release

2 release files

26.33

2 release files

26.15

2 release files

25.302

2 release files

25.298

2 release files

25.297

2 release files

1.4.1

2 release files

1.4

2 release files

1.3.8

2 release files

1.3.7

2 release files

1.3.6

2 release files

1.3.4

2 release files

1.3.3

2 release files

1.2.4

2 release files

1.2.3

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page