Skip to main content

Python IPC server for high-performance communication with Node.js applications using TCP sockets

Project description

IPC Framework - Inter-Process Communication

NPM companion License: MIT

Efficient Inter-Process Communication Framework for Python โ†” Node.js backend integration. This is the Python server package that enables seamless bidirectional communication with Node.js applications using TCP sockets.

๐Ÿ Python Server Package

This package provides the Python IPC server for communication with Node.js clients.

โœ… Production Ready Features:

  • โœ… TCP socket server (high-performance, low-latency)
  • โœ… Hierarchical application and channel management
  • โœ… Request/response and publish/subscribe patterns
  • โœ… Connection pooling and auto-reconnection support
  • โœ… Thread-safe operation with robust error handling

๐Ÿš€ Quick Start

Installation

# Install Python IPC server
pip install ipc-framework

# Install Node.js client (separate package)
npm install @ifesol/ipc-framework-nodejs

Python Server Usage

from ipc_framework import FrameworkServer, MessageType
import time

# Create server
server = FrameworkServer(host="localhost", port=8888)

# Create application and channel
app = server.create_application("my_app", "My Application")
api_channel = app.create_channel("api")

# Handle requests from Node.js clients
def handle_request(message):
    action = message.payload.get('action')
    
    if action == 'get_data':
        response = message.create_response({
            'success': True,
            'data': {'timestamp': time.time(), 'message': 'Hello from Python!'},
            'server': 'Python IPC Framework'
        })
        
        connection = server.connection_manager.get_connection(
            message.payload.get('connection_id')
        )
        server.send_to_connection(connection, response)

api_channel.set_handler(MessageType.REQUEST, handle_request)

print("๐Ÿ Python IPC Server starting on localhost:8888")
server.start()

Node.js Client Usage

const { IPCClient } = require('@ifesol/ipc-framework-nodejs');

async function main() {
    const client = new IPCClient('my_app', {
        host: 'localhost',
        port: 8888
    });

    try {
        await client.connect();
        console.log('โœ… Connected to Python server!');

        const response = await client.sendRequest('api', {
            action: 'get_data'
        });

        console.log('๐Ÿ“จ Response from Python:', response.payload);
    } catch (error) {
        console.error('โŒ Error:', error.message);
    } finally {
        client.disconnect();
    }
}

main();

๐ŸŽฏ Architecture Features

โœ… Production-Ready Server:

  • High-performance TCP sockets for low-latency communication
  • Hierarchical structure with applications and channels
  • Message routing and automatic connection management
  • Thread-safe operations with robust error handling

โœ… Communication Patterns:

  • Request/Response - Direct client-server communication
  • Publish/Subscribe - Real-time notifications and broadcasts
  • Channel-based routing - Organized message handling
  • Connection pooling - Efficient resource management

๐Ÿ—๏ธ Integration with Node.js

This Python server works seamlessly with Node.js applications. Here's how to connect an Express.js app:

Node.js Express.js Integration:

const express = require('express');
const { IPCClient } = require('@ifesol/ipc-framework-nodejs');

const app = express();
const pythonClient = new IPCClient('web_api');

app.use(express.json());

// Initialize connection to Python IPC server
pythonClient.connect().then(() => {
    console.log('๐Ÿ”— Connected to Python IPC server');
});

// API endpoint proxying to Python backend
app.post('/api/process', async (req, res) => {
    try {
        const result = await pythonClient.sendRequest('processing', {
            action: 'process_user_data',
            data: req.body,
            connection_id: pythonClient.connectionId
        });
        
        res.json(result.payload);
    } catch (error) {
        res.status(500).json({ error: error.message });
    }
});

app.listen(3000, () => {
    console.log('๐ŸŒ Express server running on port 3000');
    console.log('๐Ÿ“ก Proxying requests to Python IPC server');
});

๐Ÿ“Š Performance Characteristics

Feature Performance Details
Connection Handling Sub-millisecond Fast TCP connection establishment
Message Processing <1ms latency Direct socket communication
Concurrent Connections 100+ clients Thread-safe connection management
Message Throughput High-volume Efficient message routing
Memory Usage Low footprint Optimized Python implementation
Error Recovery Automatic Robust connection cleanup

๐ŸŽฏ Use Cases

This Python IPC server enables powerful hybrid architectures:

Backend Services

  • AI/ML model serving - Host machine learning models and serve predictions to Node.js frontends
  • Data processing pipelines - Heavy computational tasks handled by Python, coordinated with Node.js
  • Real-time analytics - Python analytics engines feeding real-time dashboards
  • Scientific computing - NumPy/SciPy computations accessible from Node.js applications

Microservice Architecture

  • Polyglot microservices - Python services integrated with Node.js API gateways
  • Event-driven architecture - Python services publishing events to Node.js consumers
  • Service mesh integration - Python backend services in cloud-native environments
  • Legacy system integration - Bridge existing Python systems with modern Node.js frontends

Hybrid Applications

  • E-commerce platforms - Python inventory/pricing engines with Node.js storefronts
  • Financial services - Python quantitative analysis with Node.js trading interfaces
  • IoT platforms - Python device controllers with Node.js monitoring dashboards
  • Chat applications - Python NLP processing with Node.js real-time messaging

๐Ÿ†š Why Choose IPC over HTTP?

HTTP API Approach IPC Framework
โŒ High latency overhead โœ… Direct TCP communication
โŒ Request/response only โœ… Request/response + pub/sub
โŒ Manual connection management โœ… Automatic reconnection
โŒ Complex error handling โœ… Built-in fault tolerance
โŒ No real-time capabilities โœ… Live notifications
โŒ Stateless limitations โœ… Persistent connections

๐Ÿ”— Companion Packages

This Python server works with the Node.js client package:

๐Ÿš€ Getting Started

  1. Install the Python server:

    pip install ipc-framework
    
  2. Install the Node.js client:

    npm install @ifesol/ipc-framework-nodejs
    
  3. Run the examples above to see the integration in action!

๐Ÿ“š Documentation

๐Ÿ“„ License

MIT License - see LICENSE file for details.

๐Ÿค Contributing

Contributions welcome! Help us improve the Python โ†” Node.js IPC communication experience.

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

ipc_framework-1.1.2.tar.gz (81.0 kB view details)

Uploaded Source

Built Distribution

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

ipc_framework-1.1.2-py3-none-any.whl (27.5 kB view details)

Uploaded Python 3

File details

Details for the file ipc_framework-1.1.2.tar.gz.

File metadata

  • Download URL: ipc_framework-1.1.2.tar.gz
  • Upload date:
  • Size: 81.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.4

File hashes

Hashes for ipc_framework-1.1.2.tar.gz
Algorithm Hash digest
SHA256 bf777063eac1373ea1f83e2b636009e66cf68b4daf94f6b1c81ea67e7decbe9b
MD5 39ec7c886e0fd447f928c00c6e73b98d
BLAKE2b-256 a4fd477ccadec725ffc64d1f8bbe4ec615e6242624ae9d82cf089f9bce3027a4

See more details on using hashes here.

File details

Details for the file ipc_framework-1.1.2-py3-none-any.whl.

File metadata

  • Download URL: ipc_framework-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 27.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.4

File hashes

Hashes for ipc_framework-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 87c42cbd4c4da9f3c00ebe8a91ac66322064f87f748ce60ed97ac53793d013e0
MD5 f9297d970cceec77aa0102ddbbe519e5
BLAKE2b-256 3851677270f787e897b42fa8ad0597d5f1864d495d9f73b6db5e778f6798a62b

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