Systems programming
PyChat
A terminal chat application in a single Python file with no dependencies: sockets, concurrency, SSL and a terminal interface, all from the standard library.
The problem
I wanted a small project that shows how computer systems fit together. With so much open-source code available, it is easy to build something impressive without understanding it, so I chose to use no third-party libraries at all.
The approach
PyChat is a multi-user chat server and client that runs in the terminal. Building it meant solving several problems in one program:
- Concurrency, with queues, threads and coroutines
- Network socket I/O, managing many connections and defining a client and server protocol
- SSL with mutual certificate verification, plus a script that generates a certificate authority and certificates
- A terminal user interface with focus handling, mouse support and scrollable chat history
- An event-driven design with publish and subscribe concepts
Everything lives in one file that needs only Python and its standard library.
Where it stands
It is a finished demonstration project, documented with a wiki, a demo video and an architecture diagram. It is meant for learning and is not intended for real-world deployment.