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.24.tar.gz
(45.9 kB
view hashes)
Built Distributions
Close
Hashes for sevent-0.4.24-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 20eecb5f3daaf71efd753818e116677a0b1f6f59612564ae94da733c685931b4 |
|
MD5 | 3501cbed0aa098db6f801839c0af2d30 |
|
BLAKE2b-256 | 49b8ea9cdbb52d483839e0d6565623dadd6a8faa4e9bbe73d11ba63bdf6f0832 |
Close
Hashes for sevent-0.4.24-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c49cd45afc735d3c7c9c0ccbaa9a735ebce2c6e278190235a101b78163bdc0ba |
|
MD5 | 751866e521fa68fe0b7be02051807135 |
|
BLAKE2b-256 | a5e27b0cf08e1424910b01b59c117488d01dcb3914806661a2d1bbb10075bffc |
Close
Hashes for sevent-0.4.24-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f1f922a08a98cbfa8b7ee459eca47c3c2db443d43c281e8546c367fded9e3a9b |
|
MD5 | 491286c313d12068b2913e295ee1817e |
|
BLAKE2b-256 | 84179c2114bbad8d7194cb3a2942996b7d9089d58e97371a6ac258e427160a0a |
Close
Hashes for sevent-0.4.24-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc7026203d11ea93deddba5128c1b74f647042d92e40607cc40a10aeb1577ccf |
|
MD5 | bc185af9c4f043405064060eb02674b5 |
|
BLAKE2b-256 | c6d7f7f5a13e5314f5c710acab53ef7ae599b553586c002a692fc84f85a9fc4a |
Close
Hashes for sevent-0.4.24-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b7b2b25507092ed70a52c1b37b0a3d499094ee5494275d5be915aeca18a5ba85 |
|
MD5 | f3f2ecc45ee1122c5eabc79b2aedb5e0 |
|
BLAKE2b-256 | 2ae18d393b3d9b6d648f2acd99eeb362f44f76ba02698d6ace5f2e6403265655 |
Close
Hashes for sevent-0.4.24-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f340f6fbe29f43f7fa60bdf37b2eed8a782e7c52807e9e32ee492752bf3bbf1 |
|
MD5 | 67cb9aae9d94d064a226143fef34c654 |
|
BLAKE2b-256 | d4fe92c60c92890c42816ea67fbdc17bcb60c3536fbc4ac9a786506aa9635bbc |