Readable, simple and fast asynchronous non-blocking network apps

Overview

Netius

Fast and readable async non-blocking network apps

Netius is a Python network library that can be used for the rapid creation of asynchronous non-blocking servers and clients. It has no dependencies, it's cross-platform, and brings some sample netius-powered servers out of the box, namely a production-ready WSGI server.

Simplicity and performance are the main drivers of this project. The codebase adheres to very strict code standards, and is extensively commented; and as far as performance is concerned, it aims to be up to par with equivalent native implementations, where PyPy can be used to provide the extra boost to raise performance up to these standards.

Bear in mind that although netius is non-blocking, it will naturally still block if the operations performed within the event loop are blocking, like reading or writing a file, which are both blocking operations in the Python standard library. Running multiple netius instances in parallel, and having a fast server like NGINX act as their reverse proxy, is one way of minimising the perceptibility of such blockages.

Installation

pip install netius

Or download the source from GitHub.

Netius has no dependencies, and is therefore cross-platform. It's compatible with PyPy, with which it benefits of performance increases up to 1.5x - 2.5x faster in most environments, when compared with running it with the cPython interpreter.

Usage

WSGI Server

import netius.servers

def app(environ, start_response):
    status = "200 OK"
    contents = "Hello World"
    content_l = len(contents)
    headers = (
        ("Content-Length", content_l),
        ("Content-Type", "text/plain"),
        ("Connection", "keep-alive")
    )
    start_response(status, headers)
    yield contents

server = netius.servers.WSGIServer(app = app)
server.serve(port = 8080)

HTTP Client

Synchronous usage

import netius.clients
result = netius.clients.HTTPClient.get_s(
    "http://www.flickr.com/",
    asynchronous = False
)
print(result["data"])

Asynchronous usage

import netius.clients

def on_partial(client, parser, data):
    print(data)

def on_message(client, parser, message):
    netius.clients.HTTPClient.cleanup_s()

netius.clients.HTTPClient.get_s(
    "http://www.flickr.com/",
    callback = on_message,
    on_data = on_partial
)

Test servers

The servers that come with netius out-of-the-box, can be tested through the command line:

Class Example
WSGIServer python -m netius.servers.wsgi
FTPServer python -m netius.servers.ftp
HelloServer MESSAGE="Hello Netius" python -m netius.extra.hello
FileServer BASE_PATH=/ python -m netius.extra.file
SMTPServer python -m netius.servers.smtp
RelaySMTPServer python -m netius.extra.smtp_r

Learn more

Basic

Advanced topics

More information can be found in the Advanced Topics page.

License

Netius is currently licensed under the Apache License, Version 2.0.

Build Automation

Build Status Build Status GitHub Coverage Status PyPi Status License

Comments
  • docs: Fix a few typos

    docs: Fix a few typos

    There are small typos in:

    • doc/leak.md
    • src/netius/common/http2.py

    Fixes:

    • Should read these rather than tese.
    • Should read resetting rather than reseting.

    Semi-automated pull request generated by https://github.com/timgates42/meticulous/blob/master/docs/NOTE.md

    opened by timgates42 2
  • HTTP Forward proxy is woking too slow on Edge and Firefox

    HTTP Forward proxy is woking too slow on Edge and Firefox

    Description

    For some reason the Forward HTTP proxy is working too slowly under Microsoft Edge and Firefox browsers. It seems as if the connections are getting into a stalled state for some reason.

    Note that this only happens for HTTP based connections and not the ones with CONNECT.

    bug p-high 
    opened by joamag 2
  • Netius HTTP2 proxy server is not working correctly under iPad Chrome

    Netius HTTP2 proxy server is not working correctly under iPad Chrome

    Description

    While using lugardajoia.com website and HTTP2 under Chrome for IPad some resources fail to load for an unknown reason. This may be related with #13.

    Notes

    This issue has yet to be verified under other iOS devices like iPhone. Ths issue does not occur under Safari for iOS.

    bug p-high 
    opened by joamag 2
  • Protocols

    Protocols

    • Initial version of the compatible protocols support
    • Major refactor in the base netius event loop structure
    • HTTP client support for protocol
    • DNS client support for protocol
    enhancement p-medium 
    opened by joamag 1
  • HTTP Client timeout

    HTTP Client timeout

    Description

    It's important to implement a proper way of "timeouting" an HTTP request so that the control flow is retuned to the caller on an error callback (just like normal HTTP error eg: 500).

    This should be a regression from the major event loop refactor taken some weeks ago.

    bug p-high 
    opened by joamag 1
  • HTTP2 stream stops in the middle of video playback on Chrome

    HTTP2 stream stops in the middle of video playback on Chrome

    Description

    Sometimes while playing multiple videos from the same source at the same time the Chrome browser gets stuck like if no DATA frames are being sent (stream blocked). This must be blamed on the proxy server.

    To reproduce this problem try to play at the same time multiple videos from:

    https://builds.stage.hive.pt/videos/

    Images

    image

    bug p-high 
    opened by joamag 1
  • TFTP Server support

    TFTP Server support

    Description

    TFTP is still used under a lot of scenarios to allow simple transfer of files. One of the most well known scenarios is the PXE boot infra-structure.

    For that a simple server under the netius infra-structure must be created.

    Links

    Wikipedia RFC 1350 Client for Windows PXELINUX

    enhancement p-high 
    opened by joamag 1
  • Get content of uploaded file in easier way than by slicing 'wsgi.input'

    Get content of uploaded file in easier way than by slicing 'wsgi.input'

    Hi!

    At first I want to thank you for great working library, which is easy to use and play nice with use cases in our projects. When file is sent to server (using Cordova File Transfer plugin) from our hybrid app, content of environment['wsgi.input'].getvalue() is:

    --+++++
    Content-Disposition: form-data; name="file"; filename="image.jpg"
    Content-Type: application/octet-stream
    
    (Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
    --+++++--
    

    And when I need to get text content of uploaded file, I have to manually slice environment['wsgi.input'] to get content (to get dispose of boundaries, Content info etc..):

    uploadedFileContent = inputWithFile.getvalue()
    uploadedFile=StringIO(uploadedFileContent[uploadedFileContent.index(START_OF_FILE_CONTENT):len(uploadedFileContent)])
    uploadedFile=StringIO(uploadedFile.getvalue([0:uploadedFile.getvalue().index(BEGINNING_OF_ADDITIONAL_INFO_AT_END_OF_FILE)])
    content = str(uploadedFile.getvalue())
    

    Is there a way in your library to get content of uploaded file out of the box, without the need to slice environment['wsgi.input'] maually?

    Thank you in advance for reply, Radek from Techmetria.

    enhancement wontfix p-medium 
    opened by radek-anuszewski 1
  • Support for multiple files in torrent server

    Support for multiple files in torrent server

    Description

    There's currently no support for multiple files in the Bit torrent Server/Client infra-structure, this support must be created.

    Reference

    BitTorrent Specification

    enhancement p-medium 
    opened by joamag 1
  • HTTP/2 support

    HTTP/2 support

    Description

    HTTP/1.1 is slow and old and a new standard must be implemented. It's going to be challenging mostly because of the required implementation of the headers compression HPACK (RFC7541).

    Notice that there's already a lot of browsers supporting this specification as seen here.

    Inspiration

    Currently the best inspiration is to use the nghttp2 library that provides support fot Python through its binding libraries.

    There's also the node-http2 (node.js implementation) quite interesting for its sinplicity.

    Estimation

    2-5 days

    References

    Attachements

    rfc7540.pdf

    enhancement p-medium 
    opened by joamag 1
  • Support for server side SSL SNI (Service Name Indication)

    Support for server side SSL SNI (Service Name Indication)

    Description

    Sometimes it's important to have a virtual hosting based serving with a different SSL certificate per each host (proxy usage). For this situations the solution is to user SNI extension to SSL that provides a way to handle this scenarios. SNI is available for Python since 3.3 but only 3.4 handles server side SNI correctly.

    Implementation

    The corre implementation implies the compatability of netius with 3.4 and the usage of the ssl.SSLContext.set_servername_callback method.

    Reference

    http://en.wikipedia.org/wiki/Server_Name_Indication https://docs.python.org/3/library/ssl.html#ssl.SSLContext.set_servername_callback

    enhancement p-high 
    opened by joamag 1
  • HTTP3 and QUIC ideas

    HTTP3 and QUIC ideas

    Rationale

    The world of HTTP is now constantly migrating and although the evolution from HTTP 1.1 to 2.0 took a lot of time the migration from 2.0 to 3.0 was quite fast.

    Netius should follow this migration path and add support for HTTP 3.0 including the implementation of the QUIC transport protocol on top of UDP.

    References

    feature-request πŸ’‘ 
    opened by joamag 0
  • Server support for protocols

    Server support for protocols

    Design changes

    • Merge of the server and client base infrastructure under common.py (server(), socket_tcp(), socket_udp())
    • More server related methods in the compact.py file

    Current Status

    • Echo UDP server already working
    • EchoProtocol is the one used for the testing

    Testing

    To run the echo server Protocol implementation using netius run:

    PYTHONPATH=. python3 netius/servers/echo.py 
    

    To use the compa version meaning that an asyncio like interface will be used underneath the hoods use:

    COMPAT=1 PYTHONPATH=. python3 netius/servers/echo.py
    

    This PR is related to #23

    enhancement risky ❕ core πŸ’Ž 
    opened by joamag 4
  • Protocols support

    Protocols support

    Description

    Since the inception of the asyncio library in Python 3.5, the Python network world has changed, and a lot of "scalability" emerged from that.

    As Netius was created before the arrival of asyncio, the tech approach to network diverged and although overall both strategies represent nonblocking asyncio event-loop based solutions, they have different approaches and abstractions for server and client implementation.

    The objective of this issue is to merge (via compatibility layer) both approaches, making it possible the following scenarios:

    • A netius HTTP should be able to run on the asyncio event loop
    • An asyncio service should be able to run in the netius event loop

    Implementation

    Architecture

    • Transport - Connection vs Connectionless (Datagram)
    • Protocol - Equivalent to part of the current Connection and also part of the current Server/Client (protocol logic)
    • Server - Equivalent to the newly created Service that spawns multiple connections (that should be converted into transports)
    • Parsers - Already exists and should remain pretty much the same
    • Event Loop - Must be improved to distance itself from the server vs client approach, meaning that a event loop is something simpler that only handles the polling strategy adapting details
    • Servers/Clients (Agents) - Must be simple Abstract API entry-points that facilitate some operations (no logic), this abstract logic should be re-use as much as possible

    Change ideas

    Command based client

    Must rethink very well what's a command-based client (eg: SMTP, IMAP, etc.) as their session is currently very hard-coded, it must be much more similar to command-based. Kind of like a bot-based server (more similar to the FTP server). And their state machine should be more flexible.

    Migration strategy

    This is the overall idea of how to migrate a client

    HTTPConnection -> HTTPProtocol
    

    Principles

    • Retro-compatibility should always be a priority
    • Concepts like auto_close and auto_pause no longer make sense
    • Bi-directional compatibility between netius and asyncio
      • Protocols developed for asyncio should be able to run without problems in netius
      • Netius server implementations should be able to run without problem in the base asyncio event loop

    Reference

    Transports and protocols (callback-based API) aiohttp server

    enhancement p-high architecture 🏚 core πŸ’Ž 
    opened by joamag 1
  • Failover on proxy server

    Failover on proxy server

    Description

    It's important to be able to handle a fallback process when a back-end server is not available. Our current proxy solutions does not handle the unavailability of the back-end server on a proper way.

    Solution

    Proper solution would imply

    • Constant "ping" of the back-end server
    • Marking the back-end server as not available
    • Not redirecting request to the unavailable services
    enhancement p-medium 
    opened by joamag 0
  • Support for Websockets in Proxy server

    Support for Websockets in Proxy server

    Description

    The current proxy infra-structure does not support the proxying of Websocket connections, this is relevant for scenarios where the connection is mixed (eg: http://rancher.hive:1001 or https://guacamole.stage.hive.pt).

    Solution

    Proper attention to the upgrade header must be done to properly handle these connections.

    References

    enhancement p-high 
    opened by joamag 0
Owner
Hive Solutions
Next-generation software boutique, built by perfectionists
Hive Solutions
RabbitMQ asynchronous connector library for Python with built in RPC support

About RabbitMQ connector library for Python that is fully integrated with the aio-pika framework. Introduction BunnyStorm is here to simplify working

null 22 Sep 11, 2022
Asynchronous For Python(asyncio)

asyncio is a library to write concurrent code using the async/await syntax.asyncio is used as a foundation for multiple Python asynchronous frameworks that provide high-performance network and web-servers, database connection libraries, distributed task queues, etc. asyncio is often a perfect fit for IO-bound and high-level structured network code.

Janak raikhola 0 Feb 5, 2022
OptiPLANT is a cloud-based based system that empowers professional and non-professional data scientists to build high-quality predictive models

OptiPLANT OptiPLANT is a cloud-based based system that empowers professional and non-professional data scientists to build high-quality predictive mod

Intellia ICT 1 Jan 26, 2022
This Tool can help enginners and biggener in network, the tool help you to find of any ip with subnet mask that can calucate them and show you ( Availble IP's , Subnet Mask, Network-ID, Broadcast-ID )

This Tool can help enginners and biggener in network, the tool help you to find of any ip with subnet mask that can calucate them and show you ( Availble IP's , Subnet Mask, Network-ID, Broadcast-ID )

null 12 Dec 13, 2022
Nautobot is a Network Source of Truth and Network Automation Platform.

Nautobot is a Network Source of Truth and Network Automation Platform. Nautobot was initially developed as a fork of NetBox (v2.10.4). Nautobot runs as a web application atop the Django Python framework with a PostgreSQL database.

Nautobot 549 Dec 31, 2022
nettrace is a powerful tool to trace network packet and diagnose network problem inside kernel.

nettrace nettrace is is a powerful tool to trace network packet and diagnose network problem inside kernel on TencentOS. It make use of eBPF and BCC.

null 84 Jan 1, 2023
PcapXray - A Network Forensics Tool - To visualize a Packet Capture offline as a Network Diagram

PcapXray - A Network Forensics Tool - To visualize a Packet Capture offline as a Network Diagram including device identification, highlight important communication and file extraction

Srinivas P G 1.4k Dec 28, 2022
Fast and configurable script to get and check free HTTP, SOCKS4 and SOCKS5 proxy lists from different sources and save them to files

Fast and configurable script to get and check free HTTP, SOCKS4 and SOCKS5 proxy lists from different sources and save them to files. It can also get geolocation for each proxy and check if proxies are anonymous.

Almaz 385 Dec 31, 2022
A simple, configurable application and set of services to monitor multiple raspberry pi's on a network.

rpi-info-monitor A simple, configurable application and set of services to monitor multiple raspberry pi's on a network. It can be used in a terminal

Kevin Kirchhoff 11 May 22, 2022
Simple P2P application for sending files over open and forwarded network ports.

FileShareV2 A major overhaul to the V1 (now deprecated) FileShare application. V2 brings major improvements in both UI and performance. V2 is now base

Michael Wang 1 Nov 23, 2021
A Simple but Powerful cross-platform port scanning & and network automation tool.

DEDMAP is a Simple but Powerful, Clever and Flexible Cross-Platform Port Scanning tool made with ease to use and convenience in mind. Both TCP

Anurag Mondal 30 Dec 16, 2022
A simple software which can use to make a server in local network

home-nas it is simple software which can use to make a server in local network, it has a web site on it which can use by multipale system, i use nginx

R ansh joseph 1 Nov 10, 2021
Simple python script for automated network scans with random name generator(useful for CTF boxes).

?? Automated NMAP script Description Simple python script for automated network scans with random name generator(useful for CTF boxes). Requirements 1

Dhmos Funk 2 Oct 29, 2021
A simple electrical network analyzer, BASED ON computer-aided design.

Electrical Network Analyzer A simple electrical network analyzer. Given the oriented graph of the electrical network (circut), BASED ON computer-aided

Ahmad Abdulrahman 4 Oct 15, 2022
Ipscanner - A simple threaded IP-Scanner written in python3 that can monitor local IP's in your network

IPScanner ?? A simple threaded IP-Scanner written in python3 that can monitor lo

null 4 Dec 12, 2022
JF⚑can - Super fast port scanning & service discovery using Masscan and Nmap. Scan large networks with Masscan and use Nmap's scripting abilities to discover information about services. Generate report.

Description Killing features Perform a large-scale scans using Nmap! Allows you to use Masscan to scan targets and execute Nmap on detected ports with

null 377 Jan 3, 2023
msgspec is a fast and friendly implementation of the MessagePack protocol for Python 3.8+

msgspec msgspec is a fast and friendly implementation of the MessagePack protocol for Python 3.8+. In addition to serialization/deserializat

Jim Crist-Harif 414 Jan 6, 2023
GlokyPortScannar is a really fast tool to scan TCP ports implemented in Python.

GlokyPortScannar is a really fast tool to scan TCP ports implemented in Python. Installation: This program requires Python 3.9. Linux

gl0ky 5 Jun 25, 2022
High capacity, high availability, well connected, fast lightning node.

LND ⚑ Routing High capacity, high availability, well connected, fast lightning node. We aim to become a top liquidity provider for the lightning netwo

null 18 Dec 16, 2022