Skip to content

Conversation

sumanjeet0012
Copy link

@sumanjeet0012 sumanjeet0012 commented Jul 4, 2025

Python Implementation of Universal Connectivity Chat Application

Overview

This PR implements a complete Python peer-to-peer chat application using libp2p and GossipSub protocol, addressing the request for a Python peer in the Universal Connectivity project.

Related Issue

Fixes: libp2p/py-libp2p#624

Implementation Details

Core Features

  • Peer-to-Peer Chat: Real-time messaging using GossipSub pubsub protocol
  • Multiple UI Modes:
    • Textual TUI interface for rich terminal experience
    • CLI mode for simple interactive chat
    • Headless mode for background operation
  • Peer Discovery: Manual connection to other peers using Multiaddr
  • System Logging: Structured logging with timestamped system events

Technical Stack

  • libp2p: Core peer-to-peer networking (py-libp2p 0.2.9)
  • Trio: Async/await framework for concurrent operations
  • Textual: Modern terminal user interface framework
  • GossipSub: Publish-subscribe messaging protocol
  • TCP Transport: Reliable connection transport (QUIC support planned)

Key Components

  • main.py - Application entry point with argument parsing
  • chatroom.py - Chat room logic and message handling
  • headless.py - Background service managing libp2p operations
  • ui.py - Textual-based terminal user interface

Usage Examples

# Start with Textual TUI
py-peer --nick "Sumanjeet" --ui

# Connect to specific peer
py-peer --nick "Devs" --connect /ip4/127.0.0.1/tcp/PORT/p2p/PEER_ID

# Headless mode
py-peer --nick "User" --headless

Testing

  • ✅ Multi-peer chat sessions tested
  • ✅ Peer discovery and connection verified
  • ✅ All UI modes functional
  • ✅ Cross-platform compatibility (Linux/macOS/Windows)

Dependencies

  • Python 3.12+
  • All dependencies managed via pyproject.toml with uv.lock for reproducible builds

Documentation

  • Comprehensive README with installation, usage, and troubleshooting
  • Architecture diagrams and component descriptions
  • Screenshot of working Textual UI interface

Additional Notes

  • Uses TCP transport currently; QUIC support may be added in future
  • Follows Python best practices with type hints and async patterns
  • Modular architecture allows easy extension and customization

- Refactored UI code to utilize trio memory channels for asynchronous communication, replacing the previous queue-based approach.
- Implemented handling of incoming and outgoing messages using async methods, improving responsiveness and error handling.
- Simplified message sending and processing logic, ensuring UI updates are handled safely within the async context.
… Textual;

integrated Janus queue for communication between service and TUI.
@sumanjeet0012
Copy link
Author

@seetadev Ready for review

@sumanjeet0012 sumanjeet0012 requested a review from a team as a code owner August 25, 2025 17:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant