lightweight event loop
Project description
sevent
The highest performance event loop.
Examples
Simple Http Client
import sevent
def on_data(s, data):
print(data.decode("utf-8"))
s = sevent.tcp.Socket()
s.on_data(on_data)
s.on_close(lambda s: sevent.current().stop())
s.connect(('www.google.com', 80))
s.write(b'GET / HTTP/1.1\r\nHost: www.google.com\r\nConnection: Close\r\nUser-Agent: curl/7.58.0\r\nAccept: */*\r\n\r\n')
sevent.instance().start()
import sevent
async def http_test():
s = sevent.tcp.Socket()
await s.connectof(('www.google.com', 80))
await s.send(b'GET / HTTP/1.1\r\nHost: www.google.com\r\nConnection: Close\r\nUser-Agent: curl/7.58.0\r\nAccept: */*\r\n\r\n')
data = b''
while True:
try:
data += (await s.recv()).read()
except sevent.tcp.SocketClosed:
break
print(data.decode("utf-8"))
await s.closeof()
sevent.run(http_test)
Simple TCP Port Forward
import sys
import sevent
def on_connection(server, conn):
pconn = sevent.tcp.Socket()
pconn.connect((sys.argv[2], int(sys.argv[3])))
conn.link(pconn)
server = sevent.tcp.Server()
server.on_connection(on_connection)
server.listen(("0.0.0.0", int(sys.argv[1])))
sevent.instance().start()
import sys
import sevent
async def tcp_port_forward_server():
server = sevent.tcp.Server()
server.listen(("0.0.0.0", int(sys.argv[1])))
while True:
conn = await server.accept()
pconn = sevent.tcp.Socket()
pconn.connect((sys.argv[2], int(sys.argv[3])))
conn.link(pconn)
sevent.run(tcp_port_forward_server)
License
sevent uses the MIT license, see LICENSE file for the details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
sevent-0.4.18.tar.gz
(44.9 kB
view hashes)
Built Distributions
Close
Hashes for sevent-0.4.18-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eec4d5a3d4cf6ee898c5a93e37ab9a591fd97c146792c191dad66041b816d448 |
|
MD5 | 8eaaaa76bd0b8a593b19a978f49c2ae1 |
|
BLAKE2b-256 | 6e6a217b8013d883680951739bef89c32443479ce0be406e12b7e7608c80f3c5 |
Close
Hashes for sevent-0.4.18-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 788379d3cd5fd8586c629c254a92ae0651a88901da088c086420a7773e4d481c |
|
MD5 | 4acd7ec7f0537b80f857c4fa64db0c71 |
|
BLAKE2b-256 | ca21d90f9839a95b2794b2f65d4adde112838dbcc2d936390a62ca898b675ec7 |
Close
Hashes for sevent-0.4.18-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d37a063726a5f4bf1f4a8da033d8f63607687c2dc1de1b9fe5da5e59bc335c7 |
|
MD5 | 5e558948d0883e03fb892471754c79d9 |
|
BLAKE2b-256 | 881a0b40a0a190f8d8094b70fa4b2de9fa631167df662017045f23b4cef95de6 |
Close
Hashes for sevent-0.4.18-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 103bf045ee5c8308268b4e584a698222c913996df6934894d8d6258aed56180c |
|
MD5 | 23ca139bf618a892d000536da66a35e9 |
|
BLAKE2b-256 | 48fa756b71cbebe03e1539e2b41dd1f86948398bf60e902727d14400997a850e |