Skip to main content

Client for sync/async query HTTP API Services

Project description

API Client HTTP

Client for sync/async query HTTP API Services. It provides a high-level interface for managing URLs, headers, and authentication. Based on HTTPX library.

Features

  • Synchronous and asynchronous HTTP requests
  • Token-based authentication
  • Customizable headers
  • URL management
  • Error handling

Installation

To install the library, use pip:

pip install api-client-http

Usage

Synchronous client

from api_client_http import RestClient
from api_client_http.auth import TokenAuth

client = RestClient(
    address="https://api.example.com/v1",
    endpoints= {
      'token': 'auth/token',
      'query': 'query/{}'
    }
)

auth_respone = client.post('token', json={'username': 'user', 'password': 'password'})
response = client.get('query', '123', auth=TokenAuth(auth_respone['access_token']))

Asynchronous client

from api_client_http import AsyncRestClient
from api_client_http.auth import TokenAuth

client = AsyncRestClient(
    address="https://api.example.com/v1",
    endpoints= {
      'token': 'auth/token',
      'query': 'query/{}'
    }
)

auth_respone = await client.post('token', json={'username': 'user', 'password': 'password'})
response = await client.get('query', '123', auth=TokenAuth(auth_respone['access_token']))

License

This project is licensed under the MIT License. See the LICENSE file for details.

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

api_client_http-1.0.0.tar.gz (7.2 kB view hashes)

Uploaded Source

Built Distribution

api_client_http-1.0.0-py3-none-any.whl (9.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page