NetworkPype is a Python library for building efficient network communication pipelines, supporting both REST and WebSocket protocols with built-in rate limiting and time synchronization.
Project description
NetworkPype
A Python library for building efficient network communication pipelines, supporting both REST and WebSocket protocols with built-in rate limiting and time synchronization.
Features
- ๐ Dual Protocol Support: Unified factory for REST and WebSocket connections
- ๐ฆ Async Rate Limiting: Built-in throttler with multiple concurrent limits and weighted consumption
- โฐ Time Synchronization: Rolling-window server time alignment for timestamp-sensitive APIs
- ๐ญ Factory Pattern:
ConnectionsFactoryandConnectionManagersFactoryfor clean lifecycle management - ๐ Processor Pipeline: Composable pre/post processors for request transformation and response handling
- ๐ก๏ธ Authentication: Abstract
Authbase class supporting any scheme (API key, OAuth, HMAC, JWT) - ๐ Type Safe: Fully typed with MyPy strict mode
- ๐งช Well Tested: Comprehensive test suite with high coverage
Installation
# Using pip
pip install networkpype
# Using uv
uv add networkpype
Quick Start
import asyncio
from decimal import Decimal
from networkpype.factory import ConnectionManagersFactory
from networkpype.rest.method import RESTMethod
from networkpype.throttler.rate_limit import RateLimit
from networkpype.throttler.throttler import AsyncThrottler
async def main():
throttler = AsyncThrottler(
rate_limits=[RateLimit(limit_id="default", limit=10, time_interval=1.0)]
)
factory = ConnectionManagersFactory(throttler=throttler)
manager = await factory.get_rest_manager()
data = await manager.execute_request(
url="https://api.example.com/v1/data",
throttler_limit_id="default",
method=RESTMethod.GET,
)
print(data)
await factory.close()
asyncio.run(main())
Core Components
-
Factory: Entry point for creating connections
ConnectionsFactory: Low-level aiohttp session managementConnectionManagersFactory: High-level managers with auth, throttling, and processors
-
REST: Full HTTP pipeline
RESTConnection: Raw aiohttp wrapperRESTManager: Orchestrates throttling, auth, and pre/post processorsRESTRequest/RESTResponse: Type-safe request and response containers
-
WebSocket: Persistent connection management
WebSocketConnection: Low-level connection with ping/pong handlingWebSocketManager: Message pipeline with auth and processorsWebSocketJSONRequest/WebSocketPlainTextRequest: Typed message types
-
Throttler: Async rate limiting
AsyncThrottler: Multi-limit, weighted rate limiterRateLimit: Declarative limit configuration with linked limitsAsyncRequestContext: Context manager for acquiring capacity
-
Auth: Authentication framework
Auth: Abstract base โ subclass to implement any authentication scheme
-
TimeSynchronizer: Server time alignment
- Rolling-window offset with median + weighted-average calculation
ConnectionManagersFactory
โโโ RESTManager
โ โโโ RESTPreProcessor[] โโ modify requests before sending
โ โโโ Auth โโ sign authenticated requests
โ โโโ RESTConnection โโ execute HTTP via aiohttp
โ โโโ RESTPostProcessor[] โโ transform responses
โโโ WebSocketManager
โโโ WebSocketPreProcessor[] โโ transform outgoing messages
โโโ Auth โโ sign authenticated messages
โโโ WebSocketConnection โโ manage WS lifecycle
โโโ WebSocketPostProcessor[] โโ process incoming messages
AsyncThrottler
โโโ RateLimit[] โโ multiple windows with linked-limit support
Documentation
Full documentation is available at gianlucapagliara.github.io/networkpype.
Development
NetworkPype uses uv for dependency management and packaging:
# Install dependencies
uv sync
# Run tests
uv run pytest
# Run type checks
uv run mypy networkpype
# Run linting
uv run ruff check .
# Run pre-commit hooks
uv run pre-commit run --all-files
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
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 networkpype-1.1.3.tar.gz.
File metadata
- Download URL: networkpype-1.1.3.tar.gz
- Upload date:
- Size: 136.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.1 {"installer":{"name":"uv","version":"0.11.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2bb78311a1461b4bc1241f2d9802698aa9a01bc6b52a8f59fac89dc28a6fdf74
|
|
| MD5 |
6d5b16794e792458219a14a5a028e85f
|
|
| BLAKE2b-256 |
6b952dc007192532b361bc612ea460e4a2c0f2e76252383f422f840ed0e5a2e6
|
File details
Details for the file networkpype-1.1.3-py3-none-any.whl.
File metadata
- Download URL: networkpype-1.1.3-py3-none-any.whl
- Upload date:
- Size: 39.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.1 {"installer":{"name":"uv","version":"0.11.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8de1545346f4248d8351e6aea57595e0c56a368264277471a6e5515111c57ad1
|
|
| MD5 |
da535946f81142c03b911f0975579020
|
|
| BLAKE2b-256 |
6c88279182bc36184b93f77665f904648a44ebee5a23308739fcc6e7ff98b7f6
|