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
Metadata
Release files for networkpype 1.1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| networkpype-1.1.5.tar.gz | 136.3 kB | Without provenance | Details for networkpype-1.1.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| networkpype-1.1.5-py3-none-any.whl | Python 3 | none | any | Details for networkpype-1.1.5-py3-none-any.whl |
Total release size: 175.8 kB
Release files / networkpype-1.1.5.tar.gz
| Download URL | networkpype-1.1.5.tar.gz |
|---|---|
| Size | 136.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6050e19589a51e4605baf35c5342b236a7ba511866b60c094d7cdfd34d0c5dd7
|
|
BLAKE2b-256 checksum How to use checksums |
ed12e52115c35857722cc433c6bc5e04db08ec4c814003e3758aa2da117f8f81
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","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}
|
Release files / networkpype-1.1.5-py3-none-any.whl
| Download URL | networkpype-1.1.5-py3-none-any.whl |
|---|---|
| Size | 39.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d6c4fa211a12aff50c39f9c176daf5a2d3b77462d53dc8b80154fdba64672b52
|
|
BLAKE2b-256 checksum How to use checksums |
2de389d93130bffa8f936992eb13aed418ede2827d3bfb0e3bd741126ccfc354
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","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}
|
Security for networkpype 1.1.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.