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.21.tar.gz
(45.8 kB
view hashes)
Built Distributions
Close
Hashes for sevent-0.4.21-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e04609c05b5c3fa057e313886e7ae975e42758034da63adb03e9ac82eca0bdf9 |
|
MD5 | 5b5a6c3d31269c06923f70f81c831d61 |
|
BLAKE2b-256 | 1dab720ab039b2eb1ac0d0a0c608ceaf9bbbaf935ad1e411d1968f42241d94ba |
Close
Hashes for sevent-0.4.21-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b1b421feb916429cc315bc8550dd73e4d412a748f8b276e55bc00febefb6365c |
|
MD5 | 27924549731b521fc95d4eda2ff1784a |
|
BLAKE2b-256 | 0d14347e65738819b23537d6f1f4d109c822f47785c56fb8c76bf980f5bf45a8 |
Close
Hashes for sevent-0.4.21-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a89ca66b9a477c68b959cd9ba581ad4a8482334f03f1a8e20dfeb146fb1f4f0a |
|
MD5 | 81f682a99ac28720a1ae32afa83bfa13 |
|
BLAKE2b-256 | cf884bb6dcb3678fa63cd756e4a6cd946f32b5657474fdd8e95f650479cc2180 |
Close
Hashes for sevent-0.4.21-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe6d549a430fa21c2feb97579658fbdad9791bc0817253ab31a14f2e37c28644 |
|
MD5 | ca404126b4e41cd264d2499902693fd0 |
|
BLAKE2b-256 | 6241bfb4e0a6c9e3d1eab68aba62938e83e70fd694cb9e5681e4f44921047ec0 |
Close
Hashes for sevent-0.4.21-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c43f7266dd856cb95924526f8dfb6dfe131bae64d445950df8ca14edcd0330b |
|
MD5 | 40ed97c07e0627f25753d46a6a7d8fc9 |
|
BLAKE2b-256 | 4c68a3905d77a8491e7e5a7330ef1658635c3273756f6d9dc1037aab0d6f5cbd |
Close
Hashes for sevent-0.4.21-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b311900ffdd7a9ccb30ca6f8f987274b989f94f41ad85acae5e1f3a0c4d17cd |
|
MD5 | aabe359f4ee5ca850a6584c12fbd3862 |
|
BLAKE2b-256 | 9bd5878e5390e8660dc34681bf1853995dc6532d14a82907b4f1dac0b4bc3446 |