🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

async-client-lib

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

async-client-lib

Asynchronous HTTP client

0.1.9
Maintainers
1

Async Client Library

publish coverage codeql pypi license

🚀 Project Overview

async-client-lib is a sophisticated Python asynchronous HTTP client library designed to provide efficient, flexible, and robust HTTP request handling. Leveraging modern Python packaging tools and best practices, this library offers a comprehensive solution for building resilient network communication interfaces.

🛠 Technology Stack

Core Technologies

  • Language: Python 3.9+
  • Async Framework: aiohttp
  • Configuration Management: pydantic
  • Retry Mechanism: backoff

Development Tools

  • Package Management: Poetry
  • Testing: pytest, pytest-asyncio
  • Code Quality:
    • Formatting: Black
    • Linting: Ruff
    • Type Checking: mypy

📂 Project Structure

async-client-main/
├── async_client/
│   ├── __init__.py       # Core library initialization
│   ├── _client.py        # Base async HTTP client implementation
│   └── _exceptions.py    # Custom exception handling
├── pyproject.toml        # Project configuration and dependencies
├── README.md             # Project documentation
└── LICENSE               # MIT License

🔧 Key Components

1. BaseClient

  • Provides core async HTTP request management
  • Supports type-safe response parsing
  • Configurable client settings

2. ClientConfig

  • Manages client configuration parameters
  • Supports SSL verification, timeouts, and host configuration

3. Error Handling

  • Custom exception classes (BaseError, ClientError)
  • Comprehensive error logging and reporting

🚀 Quick Start

Installation

pip install async-client-lib
# Or using Poetry
poetry add async-client-lib

Usage Example


from typing import List, Dict
from pydantic import BaseModel

from async_client import BaseClient, ClientConfig


class SlideShow(BaseModel):
    title: str
    author: str
    date: str
    slides: List[Dict]


class SlideShowResponse(BaseModel):
    slideshow: SlideShow


class HttpBinClient(BaseClient):

    async def get_json(self) -> SlideShow:
        url = self.get_path("json")
        resp = await self._perform_request("GET", url)
        data = self.load_schema(resp.body, SlideShowResponse)
        return data.slideshow


async def main():
    config = ClientConfig(
        HOST="https://httpbin.org",
        SSL_VERIFY=True,
        CLIENT_TIMEOUT=30,
    )
    async with HttpBinClient(config) as client:
        slideshow = await client.get_json()
        print(slideshow)


if __name__ == "__main__":
    import asyncio
    asyncio.run(main())

🛡 Development

Setup

# Install dependencies
poetry install
# Run tests
poetry run pytest
# Code quality checks
poetry run black .
poetry run ruff check .

📋 Configuration Options

ParameterDescriptionDefault
HOSTBase URL for requestsRequired
SSL_VERIFYSSL certificate verificationTrue
CLIENT_TIMEOUTRequest timeout duration30

📄 License

MIT License

📞 Contact

Aleksey Matyunin

🔖 Version

Current version: 0.1.8

Note: Always refer to the latest documentation and release notes for the most up-to-date information.

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts