A simplified socket programming toolkit for Python.
- TCP/UDP Messaging (sync and async)
- JSON over sockets
- File transfer over TCP
- Threaded server support
- CLI for quick socket actions
- Decorators and utility functions
- Build custom TCP/UDP servers quickly
- Transfer files between machines
- Send structured (JSON) data across a network
- Stream live video and audio to multiple clients (via Python or CLI)
- Share or execute code snippets over a network
- Create automated socket-based test environments
- Use CLI for local or remote debugging and diagnostics
pip install kn-sockThe project includes a Dockerfile for building a minimal image and a docker-compose.yml for orchestrating CLI and test runs. These files are kept up to date with the latest project structure.
Run kn-sock CLI directly with Docker:
# Show help
docker-compose run knsock
# Run specific commands (examples)
docker-compose run knsock tcp-server --port 8080
docker-compose run knsock tcp-client --host localhost --port 8080 --message "Hello Docker!"# Build the Docker image (uses Dockerfile)
docker-compose build
# Run all tests (uses docker-compose.yml 'test' service)
docker-compose run test
# Run specific test file
docker-compose run test pytest test/test_tcp_udp_msg.py -v# Build the image (uses Dockerfile)
docker build -t knsock:latest .
# Run interactively
docker run -it --rm -v $(pwd):/app knsock:latest bash
# Run CLI commands
docker run --rm --network host knsock:latest tcp-server --port 8080The docker-compose.yml provides two services:
- knsock: Main service for running CLI commands
- test: Service for running the test suite
This project uses pre-commit to enforce code style and quality. The configuration is in .pre-commit-config.yaml and includes hooks for Black, Flake8, mypy, and basic whitespace/EOF checks.
To install and run pre-commit hooks:
pip install pre-commit
pre-commit install # Set up git hooks
pre-commit run --all-files # Run on all filesThis ensures your code is formatted, linted, and type-checked before committing. See .pre-commit-config.yaml for details.
Have ideas or found bugs? Open an issue or submit a pull request!
If you're new:
- See the contributing guide
- Or just start with a ⭐ star :)
This project is licensed under the MIT License.
