Skip to main content

A simple, zero-dependency TCP networking library with message integrity and request/response patterns

Project description

Veltix

The networking library you always wanted

PyPI Python License

โœจ Features

  • ๐Ÿš€ Dead simple API - Get started in minutes, not hours
  • ๐Ÿ”’ Message integrity - Built-in SHA256 hash verification
  • ๐Ÿ“ฆ Custom binary protocol - Lightweight and efficient
  • ๐Ÿชถ Zero dependencies - Pure Python stdlib only
  • ๐Ÿ”Œ Extensible - Custom message types with plugin support
  • โšก Multi-threaded - Handle multiple clients automatically
  • ๐Ÿ”„ Request/Response pattern - Built-in send_and_wait with timeout support
  • ๐Ÿ“ก Built-in ping/pong - Automatic latency measurement
  • ๐Ÿ“ Integrated logging - Powerful, colorful, production-ready logger
  • ๐Ÿ›ก๏ธ Enhanced security - Improved error handling and data validation

๐Ÿ“– Why Veltix?

Existing Python networking libraries are either too low-level (raw sockets) or too complex (Twisted, asyncio). Veltix fills the gap with a simple, modern API that handles the boring parts for you.

Built by a passionate developer who wanted networking to be easy, Veltix focuses on developer experience without sacrificing power or performance.

๐Ÿš€ Installation

pip install veltix

Requirements: Python 3.10+

That's it! Zero dependencies, ready to use.

โšก Quick Start

Simple Chat Server

Server (server.py):

from veltix import Server, ServerConfig, MessageType, Request, Events

# Define message type
CHAT = MessageType(code=200, name="chat")

# Configure server
config = ServerConfig(host="0.0.0.0", port=8080)
server = Server(config)
sender = server.get_sender()


def on_message(client, response):
    print(f"[{client.addr[0]}] {response.content.decode()}")
    # Broadcast to all
    reply = Request(CHAT, f"Echo: {response.content.decode()}".encode())
    sender.broadcast(reply, server.get_all_clients_sockets())


server.set_callback(Events.ON_RECV, on_message)
server.start()

input("Press Enter to stop...")
server.close_all()

Client (client.py):

from veltix import Client, ClientConfig, MessageType, Request, Events

CHAT = MessageType(code=200, name="chat")

config = ClientConfig(server_addr="127.0.0.1", port=8080)
client = Client(config)
sender = client.get_sender()


def on_message(response):
    print(f"Server: {response.content.decode()}")


client.set_callback(Events.ON_RECV, on_message)
client.connect()

# Send message
msg = Request(CHAT, b"Hello Server!")
sender.send(msg)

input("Press Enter to disconnect...")
client.disconnect()

Run:

python server.py
python client.py  # In another terminal

๐Ÿ“ Integrated Logger

Veltix 1.2.0 includes a powerful, production-ready logging system with colorful console output and file rotation.

Basic Usage

from veltix import Logger, LoggerConfig, LogLevel

# Get logger instance (singleton)
logger = Logger.get_instance()

# Log at different levels
logger.trace("Detailed trace information")
logger.debug("Debug information")
logger.info("General information")
logger.success("Operation successful!")
logger.warning("Warning message")
logger.error("Error occurred")
logger.critical("Critical error!")

Advanced Configuration

from veltix import Logger, LoggerConfig, LogLevel
from pathlib import Path

# Configure logger
config = LoggerConfig(
    level=LogLevel.DEBUG,  # Minimum log level
    enabled=True,  # Enable/disable logging
    use_colors=True,  # Colored console output
    show_timestamp=True,  # Show timestamps
    show_caller=True,  # Show file:line info
    show_level=True,  # Show level name

    # File logging
    file_path=Path("logs/veltix.log"),  # Log file path
    file_rotation_size=10 * 1024 * 1024,  # 10MB rotation
    file_backup_count=5,  # Keep 5 backup files

    # Performance
    async_write=False,  # Async file writing
    buffer_size=100,  # Buffer size for async
)

logger = Logger.get_instance(config)

Logger Output Example

[14:23:45.123] INFO  [server.py:45] Server listening on 0.0.0.0:8080
[14:23:46.456] OK    [client.py:78] Successfully connected to server
[14:23:47.789] DEBUG [sender.py:92] Sent 156 bytes via client (request_id: a3f2...)
[14:23:48.012] WARN  [network.py:34] Connection issue occurred: ConnectionResetError
[14:23:49.345] ERROR [request.py:89] Parse error: Hash mismatch - corrupted data

Log Levels

from veltix import LogLevel

# Available levels (in order of severity)
LogLevel.TRACE  # Most detailed (5)
LogLevel.DEBUG  # Debug info (10)
LogLevel.INFO  # General info (20)
LogLevel.SUCCESS  # Success messages (25)
LogLevel.WARNING  # Warnings (30)
LogLevel.ERROR  # Errors (40)
LogLevel.CRITICAL  # Critical errors (50)

# Change level dynamically
logger.set_level(LogLevel.WARNING)  # Only show WARNING and above

Logger Features

  • Singleton pattern - One logger instance across your application
  • Colorful output - Easy-to-read colored console logs
  • File rotation - Automatic log file rotation with configurable size
  • Performance - Optional async file writing for high-throughput apps
  • Caller info - Automatic file:line tracking
  • Thread-safe - Safe for multi-threaded applications
  • Zero config - Works great out of the box with sensible defaults

๐Ÿ”„ Request/Response Pattern

Veltix supports synchronous request-response communication with send_and_wait():

Client Example

from veltix import Client, ClientConfig, MessageType, Request

# Setup
ECHO = MessageType(code=201, name="echo")
client = Client(ClientConfig(server_addr="127.0.0.1", port=8080))
client.connect()

# Send and wait for response
request = Request(ECHO, b"Hello Server!")
response = client.send_and_wait(request, timeout=5.0)

if response:
    print(f"Got response: {response.content.decode()}")
    print(f"Latency: {response.latency}ms")
else:
    print("Timeout or error")

client.disconnect()

Server Example

from veltix import Server, ServerConfig, MessageType, Request, Events

ECHO = MessageType(code=201, name="echo")
server = Server(ServerConfig(host="0.0.0.0", port=8080))


def on_message(client, response):
    # Echo back with same request_id
    reply = Request(response.type, response.content, request_id=response.request_id)
    server.get_sender().send(reply, client=client.conn)


server.set_callback(Events.ON_RECV, on_message)
server.start()

input("Press Enter to stop...")
server.close_all()

Key points:

  • Use the same request_id in the response to match the waiting request
  • The client automatically receives the response when IDs match
  • Built-in timeout support to avoid infinite waiting

๐Ÿ“ก Built-in Ping/Pong

Veltix includes automatic ping/pong functionality for measuring latency:

Client to Server Ping

from veltix import Client, ClientConfig

client = Client(ClientConfig(server_addr="127.0.0.1", port=8080))
client.connect()

# Ping the server
latency = client.ping_server(timeout=2.0)

if latency:
    print(f"Server latency: {latency}ms")
else:
    print("Ping timeout")

client.disconnect()

Server to Client Ping

from veltix import Server, ServerConfig, Events

server = Server(ServerConfig(host="0.0.0.0", port=8080))


def on_connect(client):
    # Ping client when they connect
    latency = server.ping_client(client, timeout=2.0)
    if latency:
        print(f"Client {client.addr} latency: {latency}ms")


server.set_callback(Events.ON_CONNECT, on_connect)
server.start()

input("Press Enter to stop...")
server.close_all()

Features:

  • Automatic PING/PONG handling (no manual implementation needed)
  • Returns latency in milliseconds
  • Built-in timeout support
  • Works bidirectionally (client โ†” server)

๐Ÿ“ฆ Examples

More examples in examples/:

  • Echo Server - Simple echo implementation with send_and_wait
  • Chat Server - Simple Chat in < 80 lines
  • Ping Example - Latency measurement demonstrations

๐ŸŽฏ Advanced Features

Custom Message Types

from veltix import MessageType

# System messages (0-199)
PING = MessageType(0, "ping", "System ping message")

# User messages (200-499)
CHAT = MessageType(200, "chat", "Chat message")
FILE_TRANSFER = MessageType(201, "file", "File transfer")

# Plugin messages (500+)
CUSTOM_PLUGIN = MessageType(500, "plugin", "Custom plugin message")

Event Callbacks

from veltix import Server, Events

server = Server(config)

# Bind to connection event
server.set_callback(Events.ON_CONNECT, lambda client: print(f"Client connected: {client.addr}"))

# Bind to message event
server.set_callback(Events.ON_RECV, lambda client, msg: print(f"Message from {client.addr}"))

Broadcasting

# Broadcast to all connected clients
message = Request(CHAT, b"Server announcement!")
sender.broadcast(message, server.get_all_clients_sockets())

# Broadcast to all except specific clients
sender.broadcast(message, server.get_all_clients_sockets(), except_clients=[client1.conn])

๐Ÿ“Š Comparison

Feature Veltix socket asyncio Twisted
Easy API โœ… โŒ โš ๏ธ โŒ
Zero deps โœ… โœ… โœ… โŒ
Custom protocol โœ… โŒ โŒ โš ๏ธ
Message integrity โœ… โŒ โŒ โŒ
Multi-threading โœ… โŒ โŒ โœ…
Request/Response โœ… โŒ โš ๏ธ โœ…
Built-in ping/pong โœ… โŒ โŒ โŒ
Integrated logger โœ… โŒ โš ๏ธ โœ…

๐Ÿ—บ๏ธ Roadmap

v1.2.0 - Logging & Stability (February 2026) โœ…

  • Integrated powerful logging system with colors and file rotation
  • Enhanced error handling throughout the codebase
  • Improved sender with better broadcasting capabilities
  • API improvements: set_callback() instead of bind(), Events enum
  • Better security and data validation
  • Foundation for v1.3.0 handshake system
  • Status: RELEASED

v1.3.0 - Handshake & Authentication (March 2026)

  • Connection handshake protocol (HELLO messages)
  • Client authentication system
  • Server-side client validation
  • Protocol version negotiation
  • Status: IN DEVELOPMENT

v2.0.0 - Security (Summer 2026)

  • End-to-end encryption (ChaCha20 + X25519 + Ed25519)
  • Automatic key exchange
  • Perfect forward secrecy
  • Status: PLANNED

v3.0.0 - Performance (Fall 2026)

  • Rust core via PyO3
  • 10-100x speed improvements
  • Advanced optimizations
  • Status: RESEARCH

v4.0.0+ (2027+)

  • UDP support
  • Plugin ecosystem
  • Compression
  • WebSocket bridge

๐Ÿ†• What's New in 1.2.0

Major Changes

  • ๐ŸŽจ Integrated Logger: Production-ready logging with colors, file rotation, and async writing
  • ๐Ÿ”ง API Improvements: set_callback() replaces bind(), new Events enum
  • ๐Ÿ›ก๏ธ Enhanced Security: Better error handling and data validation throughout
  • ๐Ÿ“ก Improved Sender: Enhanced broadcasting with exclusion lists
  • ๐Ÿ“ Comprehensive Logging: Detailed logs at every level for easier debugging
  • ๐Ÿ—๏ธ Foundation for v1.3.0: Prepared infrastructure for handshake system

Breaking Changes

  • bind() โ†’ set_callback()
  • Bindings โ†’ Events

Migration Guide

# Old (v1.1.x)
from veltix import Bindings

server.bind(Bindings.ON_RECV, callback)

# New (v1.2.0)
from veltix import Events

server.set_callback(Events.ON_RECV, callback)

๐Ÿค Contributing

We welcome contributions! See CONTRIBUTING.md for guidelines.

Quick ways to help:

  • โญ Star the project
  • ๐Ÿ› Report bugs
  • ๐Ÿ“š Improve documentation
  • ๐Ÿ’ป Submit pull requests
  • ๐Ÿ’ฌ Join discussions

๐Ÿ™ Contributors

Core Team

  • Nytrox - Creator & Lead Developer

Community Heroes

Thank you to everyone who has contributed through code, documentation, bug reports, and support!

Want to be listed here? Check out our Contributing guide!

๐Ÿ“„ License

MIT License - see LICENSE file for details.

๐Ÿ”— Links


Built with โค๏ธ by Nytrox

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

veltix-1.2.0.tar.gz (33.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

veltix-1.2.0-py3-none-any.whl (27.3 kB view details)

Uploaded Python 3

File details

Details for the file veltix-1.2.0.tar.gz.

File metadata

  • Download URL: veltix-1.2.0.tar.gz
  • Upload date:
  • Size: 33.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for veltix-1.2.0.tar.gz
Algorithm Hash digest
SHA256 a0628731bd2a8e49c407e1f2328f2d106070d2cbf96f6709d76865f0d8501904
MD5 3bb2a4e739e4f9b9745f2ec41614e51a
BLAKE2b-256 a606c259b272a64910a7fd245b829f17e15bfd2c68da0234769b0f3d110efaff

See more details on using hashes here.

File details

Details for the file veltix-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: veltix-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 27.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for veltix-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2ecf3f3d61a40eb8c0f2d3620b7e6b9da5703ecae1f72c411387553671bcccb2
MD5 24b4413bedb0a4abce810cfadd8b8113
BLAKE2b-256 64a01d26ee4c04258983054e3592d329641eddf76218a3559cd761ddbd992b48

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page