Modern WebSocket framework inspired by aiogram
Project description
aiows
Modern WebSocket framework inspired by aiogram. Built for developers who ship fast.
Install
pip install aiows
Quick Start
from aiows import WebSocketServer, Router, ChatMessage, WebSocket
router = Router()
@router.connect()
async def on_connect(websocket: WebSocket):
await websocket.send_json({"type": "welcome"})
@router.message("chat")
async def handle_chat(websocket: WebSocket, message: ChatMessage):
await websocket.send_json({
"type": "response",
"text": f"Echo: {message.text}"
})
server = WebSocketServer()
server.include_router(router)
server.run("localhost", 8000)
That's it. Your WebSocket server is running.
Real Features
Authentication
from aiows import AuthMiddleware
auth = AuthMiddleware("your-secret-key")
server.add_middleware(auth)
# Connect with: ws://localhost:8000?token=user123your-secret-key
Rate Limiting
from aiows import RateLimitingMiddleware
rate_limit = RateLimitingMiddleware(max_messages_per_minute=60)
server.add_middleware(rate_limit)
SSL/TLS Support
server = WebSocketServer()
server.run("localhost", 8443, ssl=True) # Auto-generates dev certs
Production Config
from aiows import create_production_server
server = create_production_server()
server.include_router(router)
server.run()
Message Types
from aiows import BaseMessage, ChatMessage, JoinRoomMessage
@router.message("join")
async def handle_join(websocket: WebSocket, message: JoinRoomMessage):
room_id = message.room_id
user_name = message.user_name
# Handle room join logic
Health Checks
from aiows import setup_health_checks
health_checker = setup_health_checks(server, http_port=9000)
# GET /health returns server status
Connection Stats
@router.message("stats")
async def get_stats(websocket: WebSocket, message):
stats = server.get_connection_stats()
await websocket.send_json(stats)
Graceful Shutdown
Built-in. Press Ctrl+C and all connections close properly.
# Or programmatically
await server.shutdown(timeout=30)
Configuration
Environment variables or config objects:
from aiows import AiowsSettings
settings = AiowsSettings(profile="production")
server = WebSocketServer.from_settings(settings)
Middleware Stack
Order matters:
server.add_middleware(LoggingMiddleware())
server.add_middleware(ConnectionLimiterMiddleware())
server.add_middleware(AuthMiddleware("secret"))
server.add_middleware(RateLimitingMiddleware(60))
Error Handling
from aiows.exceptions import MessageValidationError
@router.message("data")
async def handle_data(websocket: WebSocket, message):
try:
result = process_data(message)
await websocket.send_json({"result": result})
except MessageValidationError:
await websocket.send_json({"error": "Invalid data"})
Examples
Check /examples for:
- Secure chat with SSL
- Authentication flow
- Middleware configuration
- Production deployment
Why aiows?
- Fast setup: 5 lines to working server
- Security features: SSL, auth, rate limiting, health checks
- Type safe: Full type hints, Pydantic validation
- Async native: Built on asyncio, handles thousands of connections
- Middleware system: Compose functionality like Express.js
- Zero config: Works out of box, configurable when needed
Roadmap
- Simplify middleware execution system
- Fix connection management race conditions
- Add rooms/channels functionality
- Implement message filters
- Optimize WebSocket performance locks
- Add connection pooling support
- Improve error handling consistency
- Add broadcasting capabilities
- Performance benchmarking suite
- Enhanced documentation
License
MIT
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
aiows-0.1.0.tar.gz
(95.8 kB
view details)
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
aiows-0.1.0-py3-none-any.whl
(47.2 kB
view details)
File details
Details for the file aiows-0.1.0.tar.gz.
File metadata
- Download URL: aiows-0.1.0.tar.gz
- Upload date:
- Size: 95.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8eaaf4accc0329b9b789bab6d9a26f0bc4e43bc49e833639b4dbbbbced5fd9e8
|
|
| MD5 |
6914ba212846c24000ed657c2e165ae4
|
|
| BLAKE2b-256 |
ace9ea8e43709addfd2045ca6384635238ee0e96f73b5ed7dc1e31edad910430
|
File details
Details for the file aiows-0.1.0-py3-none-any.whl.
File metadata
- Download URL: aiows-0.1.0-py3-none-any.whl
- Upload date:
- Size: 47.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c6ed391316be5d602ffbfc06ac3f427ff57531b797d7afe27ae9ef3f4d17087a
|
|
| MD5 |
0c79336e675f28f4ad508699a718ebaf
|
|
| BLAKE2b-256 |
4676e935d7cbfb825495f358bf7e0d2d67afd03608e24535322a97804420b4e1
|