Skip to main content

A reusable network kit for dynamic API requests.

Project description

Network Layer Library

The Network Layer Library is a Python package designed to provide a structured, reusable, and extensible way to handle HTTP requests and responses. Built on top of the powerful httpx library, it enables efficient and modern asynchronous HTTP communication.


Features

  • Async Support: Fully asynchronous client for high-performance HTTP operations using httpx.
  • Configurable Endpoints: Easily define and reuse endpoints with custom headers, parameters, and HTTP methods.
  • Centralized Logging: Built-in structured logging for requests and responses using structlog.
  • Error Handling: Comprehensive error management for authentication, rate limiting, timeouts, and other issues.
  • Flexible Configuration: Customize headers, timeouts, and cookie handling.
  • Poetry & Pip Friendly: Designed to work seamlessly with poetry for managing dependencies and publishing, while remaining compatible with pip for installation.

Installation

Install from PyPI

You can install the package using pip:

pip install network-layer

Install Locally Using Poetry

If you are using poetry for dependency management:

poetry add network-layer

Usage

Setting Up the Client

from network_layer import NetworkClient

# Initialize the client
client = NetworkClient(base_url="https://example.com")
await client.setup()

Creating Custom Endpoints

from network_layer import AsyncEndpoint
from typing import Optional, Dict, Any

class MyCustomEndpoint(AsyncEndpoint):
    @property
    def path(self) -> str:
        return "api/v1/resource"

    @property
    def method(self) -> str:
        return "GET"

    @property
    def params(self) -> Optional[Dict[str, Any]]:
        return {"key": "value"}

    @property
    def headers(self) -> Optional[Dict[str, str]]:
        return {"Authorization": "Bearer token"}

Making a Request

endpoint = MyCustomEndpoint()
response = await endpoint.execute(client)
print(response.json())
await client.close()

Development

Running Tests

Tests are located in the tests/ directory. Use pytest to run them:

pytest

Building the Package

To build the package for distribution:

poetry build

Publishing to PyPI

Make sure you’re logged into PyPI via Poetry:

poetry config pypi-token.pypi <your-token>
poetry publish --build

Why Use This Library?

  1. Built on httpx: Leveraging the power and simplicity of the httpx library, this package adds structure and extensibility for advanced use cases.
  2. Poetry-Compatible: Designed to work seamlessly with poetry, enabling easier dependency management and publishing workflows, while remaining fully compatible with pip.
  3. Asynchronous by Design: Supports high-performance asynchronous programming for modern Python applications.

License

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


Contributing

Contributions are welcomed! Please fork the repository and submit a pull request.


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

network_layer-0.1.0.tar.gz (12.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

network_layer-0.1.0-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file network_layer-0.1.0.tar.gz.

File metadata

  • Download URL: network_layer-0.1.0.tar.gz
  • Upload date:
  • Size: 12.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.10.12 Linux/5.15.167.4-microsoft-standard-WSL2

File hashes

Hashes for network_layer-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9559ef877935f691a6f7311695b7c7d1ee2d77e3bb2b44ce701bdf7f9af5915e
MD5 869cc00d2f30c54b287ee6d607ea8a28
BLAKE2b-256 26122c6c824b096c72a483ad1fd8b0c635353f661d9f8a30f4d289c272f4e4c8

See more details on using hashes here.

File details

Details for the file network_layer-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: network_layer-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.10.12 Linux/5.15.167.4-microsoft-standard-WSL2

File hashes

Hashes for network_layer-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3252177e5a73a108cb0d110147dff47817116883b28bc580da2a6307488b5816
MD5 f19bfbb9605b43d4b1ea0e8e35cca900
BLAKE2b-256 ccd7e71c4302e62c2e2ce6aec131956df2252f9d713f9baa617fae1c2004fe4f

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