PyFaye
A Python-based real-time messaging system with WebSocket support, perfect for building collaborative applications. Features server and client implementations with easy integration for scalable real-time communication in Python applications.
Links
Features
Python Native
Built specifically for Python with clean, idiomatic APIs and full type hints support.
Server & Client
Complete implementation including both server and client components for full-stack solutions.
WebSocket Support
High-performance WebSocket implementation for low-latency real-time communication.
Pub/Sub Messaging
Publish-subscribe pattern with channel-based message routing and filtering.
Authentication
Flexible authentication system with support for custom auth providers and JWT tokens.
Scalable Architecture
Designed for horizontal scaling with support for Redis backend and clustering.
Getting Started
Installation
Install PyFaye from PyPI:
pip install pyfaye
Server Setup
1from pyfaye import PyFayeServer
2import asyncio
3
4async def main():
5 server = PyFayeServer('localhost', 8000)
6
7 @server.on_connect
8 async def on_connect(client):
9 print(f'Client connected: {client.id}')
10
11 @server.on_disconnect
12 async def on_disconnect(client):
13 print(f'Client disconnected: {client.id}')
14
15 await server.start()
16 print('PyFaye server running on ws://localhost:8000')
17
18if __name__ == '__main__':
19 asyncio.run(main())
Client Usage
1from pyfaye import PyFayeClient
2import asyncio
3
4async def main():
5 client = PyFayeClient('ws://localhost:8000')
6
7 await client.connect()
8 print('Connected to PyFaye server')
9
10 # Subscribe to a channel
11 await client.subscribe('/chat/room1', callback=lambda msg: print(f'Received: {msg}'))
12
13 # Publish a message
14 await client.publish('/chat/room1', {
15 'user': 'Python User',
16 'message': 'Hello from Python!'
17 })
18
19 await asyncio.sleep(5)
20 await client.disconnect()
21
22if __name__ == '__main__':
23 asyncio.run(main())
Advanced Features
Message Filtering
Advanced message filtering capabilities with custom filter functions and channel patterns.
Presence Tracking
Track user presence and availability across channels with automatic cleanup.
Rate Limiting
Built-in rate limiting to prevent abuse and ensure fair resource usage.
Message History
Optional message persistence and history retrieval for channels.
Use Cases
Real-time Collaboration
Build collaborative editing tools, shared whiteboards, and team communication platforms.
Live Dashboards
Create real-time monitoring dashboards that update automatically as data changes.
IoT Applications
Connect IoT devices and sensors with real-time data streaming and control.
Gaming Backends
Implement multiplayer game servers with real-time player synchronization and communication.
Performance
PyFaye is built for performance with async/await support, efficient message routing, and minimal memory footprint. It can handle thousands of concurrent connections with low latency and high throughput.