netcrypt: Secure Socket Communication & Encrypted Tunneling for Python



This content originally appeared on DEV Community and was authored by Raghava Chellu

Overview

In today’s distributed systems and cloud-native apps, data-in-transit security is no longer optional — it’s mandatory. Whether you’re sending files, running IoT services, or just building a secure messaging protocol, you need encryption that’s easy to set up and hard to break.

That’s why I built netcrypt, a Python library for encrypted sockets and tunneling. It combines the simplicity of Python sockets with the strength of AES and RSA encryption, making it easier than ever to secure your networked applications.

Features

  • AES & Fernet Encryption — fast symmetric encryption for secure data-in-transit.
  • RSA Key Generation — asymmetric encryption support for key exchange & signing.
  • Encrypted TCP Sockets — secure client-server communication with minimal boilerplate.
  • Secure Tunneling — simple CLI to spin up encrypted tunnels (client/server).
  • Threaded Mode — run tunnels in the background for persistent services.
  • CLI Tools — manage keys, tunnels, and sessions directly from the terminal.

Installation

pip install netcrypt

Usage Examples

Generate AES Key
netcrypt keygen --generate --keyfile aes.key

Start a Secure Tunnel

Server:

netcrypt tunnel --mode server --keyfile aes.key --host 0.0.0.0 --port 9000
Client:

netcrypt tunnel --mode client --keyfile aes.key --host 127.0.0.1 --port 9000

Generate RSA Key Pair

netcrypt rsagen --out-private rsa_private.pem --out-public rsa_public.pem

Project Structure

netcrypt/
├── encryptors.py     # AES, RSA, Fernet encryption logic
├── key_manager.py    # Key handling & persistence
├── sockets.py        # Secure socket wrappers
├── tunnel.py         # Encrypted tunnel orchestration
├── cli.py            # Command-line interface
└── __init__.py

Run Tests

pytest tests/

Why Use netcrypt?

  • Secure-by-default — avoids insecure defaults, ships with AES-256 and RSA baked in.
  • Developer-friendly — run tunnels or manage keys with one-liners.
  • Lightweight — no heavy external dependencies, just clean Python.
  • Versatile — works for IoT devices, cloud services, or local dev setups.

License

MIT © 2025 Raghava Chellu

Installation

pip install netcrypt


This content originally appeared on DEV Community and was authored by Raghava Chellu