Skip to main content

A Network Protocol Framework

Project description

Netcore

status PyPI - Version

English | 简体中文

Netcore is a lightweight communication framework that enables concurrent message transmission over a single connection. By implementing a message chunking and scheduling mechanism similar to CPU time-slicing, it allows multiple messages to be sent and received simultaneously without establishing multiple connections.

Core Features

  • Concurrent Message Transmission

    • Single connection handles multiple concurrent messages
    • Automatic message chunking and reassembly
    • Message scheduling and prioritization
    • Non-blocking message transmission
  • Smart Message Management

    • Unique message ID tracking
    • Automatic message queuing
    • Message priority handling
    • Message completion verification
  • Protocol Layer

    • Binary protocol with message chunking
    • Support for JSON and raw data formats
    • Configurable chunk sizes
    • Memory and file-based storage options
  • Transport Layer Abstraction

    • Universal transport interface
    • Asynchronous data transmission
    • Thread safety mechanisms
    • Custom transport support

Advanced Features

  • Blueprint System

    • Route grouping and prefixing
    • Modular application structure
    • Middleware support at blueprint level
    • Isolated error handling per blueprint
  • Event System

    • Event subscription and publishing
    • One-time event handlers
    • System event monitoring
    • Asynchronous event processing
  • Task Scheduler

    • Delayed task execution
    • Periodic task scheduling
    • Priority-based scheduling
    • Thread-safe task management
  • Cache System

    • In-memory caching
    • TTL (Time-To-Live) support
    • Automatic cache cleanup
    • Thread-safe operations

Quick Start

Server Example

from netcore import Endpoint, Pipe, Response, request
import socket

# Create TCP server
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind(('localhost', 8080))
server.listen(5)
conn, addr = server.accept()

# Create pipe and endpoint
pipe = Pipe(conn.recv, conn.send)
endpoint = Endpoint(pipe)

# Register handlers for concurrent messages
@endpoint.request('message1')
def handle_message1():
    # This handler can run while other messages are being processed
    return Response('message1', {"status": "processed"})

@endpoint.request('message2')
def handle_message2():
    # Another concurrent handler
    return Response('message2', {"status": "processed"})

# Start service
endpoint.start()

Client Example

from netcore import Endpoint, Pipe, Response, request
import socket

# Connect to server
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect(('localhost', 8080))

# Create pipe and endpoint
pipe = Pipe(client.recv, client.send)
endpoint = Endpoint(pipe)

# Start client (non-blocking)
endpoint.start(block=False)

# Send multiple messages concurrently
endpoint.send('message1', {"data": "First message"})
endpoint.send('message2', {"data": "Second message"})
# Both messages will be processed concurrently

Advanced Usage Examples

Blueprint Example

from netcore import Endpoint, Blueprint, Response, request

# Create a blueprint for user-related routes
user_bp = Blueprint("users", "/user")

@user_bp.request("/list")
def user_list():
    return Response("/user/list", {"users": ["user1", "user2"]})

# Register blueprint to endpoint
endpoint.register_blueprint(user_bp)

Event System Example

# Subscribe to events
@endpoint.event.on('start')
def on_start():
    print("Service started")

# One-time event
@endpoint.event.once('initialize')
def on_init():
    print("First-time initialization")

# Emit events
endpoint.event.emit('custom_event', data={"type": "notification"})

Task Scheduler Example

# Schedule periodic task
def periodic_check():
    print("Performing periodic check")

endpoint.scheduler.schedule(periodic_check, delay=5, interval=60)  # Run every 60s after 5s delay

Cache System Example

# Cache expensive operations
@endpoint.request('/data')
def get_data():
    # Try to get from cache
    data = endpoint.cache.get("expensive_data")
    if data is None:
        # Compute and cache for 5 minutes
        data = compute_expensive_data()
        endpoint.cache.set("expensive_data", data, ttl=300)
    return Response("/data", data)

How It Works

  1. Message Chunking: Large messages are automatically split into smaller chunks
  2. Concurrent Processing: Each message is processed independently
  3. Scheduling: Chunks from different messages are interleaved for efficient transmission
  4. Reassembly: Message chunks are automatically reassembled at the destination

Documentation

For detailed documentation, visit https://netcore.acdp.top

License

This project is licensed under the MIT License. See the LICENSE file for details.

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

netcore-0.1.1.tar.gz (19.6 kB view details)

Uploaded Source

Built Distribution

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

netcore-0.1.1-py3-none-any.whl (20.1 kB view details)

Uploaded Python 3

File details

Details for the file netcore-0.1.1.tar.gz.

File metadata

  • Download URL: netcore-0.1.1.tar.gz
  • Upload date:
  • Size: 19.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.11

File hashes

Hashes for netcore-0.1.1.tar.gz
Algorithm Hash digest
SHA256 c77b1b32ed6243260bf978052131d2e79907acb29116c6b5f18979ca54c52844
MD5 af9a305fff030e3b4568d25a4112bdba
BLAKE2b-256 4507bd54237febf0009f9d710bbea64400e0c777731dc21d2ba628300b26b116

See more details on using hashes here.

File details

Details for the file netcore-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: netcore-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 20.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.11

File hashes

Hashes for netcore-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 859a360e0c9245ef30f45d7181427e72994684b0341e2f884090e0e4ee10fd81
MD5 08aa21b9be1ea39ba3edd6421a429f38
BLAKE2b-256 0566811f2ae3c1982cb1ad2d3445df8e03da5ea9593413e9d79332a8c6a35fcb

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