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
poetryfor managing dependencies and publishing, while remaining compatible withpipfor 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?
- Built on
httpx: Leveraging the power and simplicity of thehttpxlibrary, this package adds structure and extensibility for advanced use cases. - Poetry-Compatible: Designed to work seamlessly with
poetry, enabling easier dependency management and publishing workflows, while remaining fully compatible withpip. - 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9559ef877935f691a6f7311695b7c7d1ee2d77e3bb2b44ce701bdf7f9af5915e
|
|
| MD5 |
869cc00d2f30c54b287ee6d607ea8a28
|
|
| BLAKE2b-256 |
26122c6c824b096c72a483ad1fd8b0c635353f661d9f8a30f4d289c272f4e4c8
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3252177e5a73a108cb0d110147dff47817116883b28bc580da2a6307488b5816
|
|
| MD5 |
f19bfbb9605b43d4b1ea0e8e35cca900
|
|
| BLAKE2b-256 |
ccd7e71c4302e62c2e2ce6aec131956df2252f9d713f9baa617fae1c2004fe4f
|