cycls 0.0.2.11__py3-none-any.whl → 0.0.2.13__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
cycls/cycls.py
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
from fastapi import FastAPI, Request
|
|
2
|
-
from fastapi.responses import StreamingResponse
|
|
2
|
+
from fastapi.responses import StreamingResponse
|
|
3
3
|
from pydantic import BaseModel
|
|
4
|
+
from typing import List, Dict, Optional
|
|
4
5
|
|
|
5
6
|
from functools import wraps
|
|
6
7
|
import uvicorn, socket, httpx
|
|
7
8
|
import inspect
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
import logging
|
|
11
|
+
logging.basicConfig(level=logging.ERROR)
|
|
11
12
|
|
|
12
13
|
import os
|
|
13
14
|
current_dir = os.path.dirname(os.path.abspath(__file__))
|
|
14
|
-
key_path = os.path.join(current_dir, '
|
|
15
|
-
# print(key_path)
|
|
15
|
+
key_path = os.path.join(current_dir, 'tuns')
|
|
16
16
|
|
|
17
|
-
from typing import List, Dict
|
|
18
17
|
class Message(BaseModel):
|
|
19
18
|
handle: str
|
|
20
19
|
content: str
|
|
21
|
-
|
|
20
|
+
id: str
|
|
21
|
+
history: Optional[List[Dict[str, str]]] = None
|
|
22
22
|
|
|
23
23
|
def find_available_port(start_port):
|
|
24
24
|
port = start_port
|
|
@@ -28,86 +28,88 @@ def find_available_port(start_port):
|
|
|
28
28
|
return port
|
|
29
29
|
port += 1
|
|
30
30
|
|
|
31
|
+
import asyncssh, asyncio
|
|
32
|
+
|
|
33
|
+
async def create_ssh_tunnel(x,y,z='tuns.sh'):
|
|
34
|
+
try:
|
|
35
|
+
async with asyncssh.connect(z,client_keys=[key_path],known_hosts=None) as conn:
|
|
36
|
+
listener = await conn.forward_remote_port(x, 80, 'localhost', y)
|
|
37
|
+
print("✦/✧","tunnel\n")
|
|
38
|
+
await listener.wait_closed()
|
|
39
|
+
except (OSError, asyncssh.Error) as e:
|
|
40
|
+
print("✦/✧",f"tunnel disconnected: {e}")
|
|
41
|
+
|
|
42
|
+
def register(handles, network, url, mode):
|
|
43
|
+
try:
|
|
44
|
+
with httpx.Client() as client:
|
|
45
|
+
response = client.post(f"{network}/register", json={"handles":handles, "url":url, "mode":mode})
|
|
46
|
+
if response.status_code==200:
|
|
47
|
+
data = (response.json()).get("content")
|
|
48
|
+
for i in data:print(f"✦/✧ {i[0]} / {network}/{i[1]}")
|
|
49
|
+
else:
|
|
50
|
+
print("✦/✧ failed to register ⚠️")
|
|
51
|
+
except Exception as e:
|
|
52
|
+
print(f"An error occurred: {e}")
|
|
53
|
+
|
|
54
|
+
async def run_server(x,y):
|
|
55
|
+
config = uvicorn.Config(x, host="127.0.0.1", port=y, log_level="error")
|
|
56
|
+
server = uvicorn.Server(config)
|
|
57
|
+
await server.serve()
|
|
58
|
+
|
|
31
59
|
class Cycls:
|
|
32
|
-
def __init__(self,network="https://cycls.com", port=find_available_port(8001)
|
|
33
|
-
|
|
60
|
+
def __init__(self, url="", network="https://cycls.com", port=find_available_port(8001)):
|
|
61
|
+
import uuid
|
|
62
|
+
self.subdomain = str(uuid.uuid4())[:8]
|
|
34
63
|
self.server = FastAPI()
|
|
35
64
|
self.network = network
|
|
36
65
|
self.port = port
|
|
37
66
|
self.url = url
|
|
38
|
-
self.
|
|
67
|
+
self.apps = {}
|
|
39
68
|
|
|
40
69
|
def __call__(self, handle):
|
|
41
|
-
self.handle = handle
|
|
42
70
|
def decorator(func):
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
def sync_wrapper(*args, **kwargs):
|
|
53
|
-
return func(*args, **kwargs)
|
|
54
|
-
self.server.post('/main')(sync_wrapper)
|
|
55
|
-
self.publish()
|
|
56
|
-
return sync_wrapper
|
|
71
|
+
@wraps(func)
|
|
72
|
+
async def async_wrapper(*args, **kwargs):
|
|
73
|
+
return await func(*args, **kwargs)
|
|
74
|
+
@wraps(func)
|
|
75
|
+
def sync_wrapper(*args, **kwargs):
|
|
76
|
+
return func(*args, **kwargs)
|
|
77
|
+
wrapper = async_wrapper if inspect.iscoroutinefunction(func) else sync_wrapper
|
|
78
|
+
self.apps["@"+handle] = wrapper
|
|
79
|
+
return wrapper
|
|
57
80
|
return decorator
|
|
58
|
-
|
|
59
|
-
def
|
|
81
|
+
|
|
82
|
+
async def gateway(self, request: Request):
|
|
83
|
+
data = await request.json()
|
|
84
|
+
handle = data.get('handle')
|
|
85
|
+
if handle in self.apps:
|
|
86
|
+
func = self.apps[handle]
|
|
87
|
+
message = Message(**data)
|
|
88
|
+
return await func(message) if inspect.iscoroutinefunction(func) else func(message)
|
|
89
|
+
return {"error": "Handle not found"}
|
|
90
|
+
|
|
91
|
+
def push(self):
|
|
92
|
+
self.server.post("/gateway")(self.gateway)
|
|
93
|
+
asyncio.run(self.publish())
|
|
94
|
+
|
|
95
|
+
async def publish(self):
|
|
60
96
|
prod=False
|
|
61
97
|
if self.url != "":
|
|
62
98
|
prod=True
|
|
63
99
|
|
|
64
|
-
|
|
100
|
+
print(f"✦/✧ serving at port: {self.port}")
|
|
65
101
|
if prod:
|
|
66
|
-
print("✦/✧","production mode
|
|
102
|
+
print("✦/✧",f"production mode | url: {self.url}")
|
|
103
|
+
register(list(self.apps.keys()), self.network, self.url+"/gateway", "prod")
|
|
67
104
|
else:
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
with ThreadPoolExecutor() as executor:
|
|
77
|
-
if not prod:
|
|
78
|
-
self.register('dev')
|
|
79
|
-
executor.submit(self.tunnel)
|
|
80
|
-
else:
|
|
81
|
-
self.register('prod')
|
|
82
|
-
|
|
83
|
-
if self.debug:
|
|
84
|
-
executor.submit(uvicorn.run(self.server, host="127.0.0.1", port=self.port)) # perhaps keep traces?
|
|
85
|
-
else:
|
|
86
|
-
executor.submit(uvicorn.run(self.server, host="127.0.0.1", port=self.port, log_level="critical")) # perhaps keep traces?
|
|
87
|
-
|
|
88
|
-
def register(self, mode):
|
|
89
|
-
try:
|
|
90
|
-
with httpx.Client() as client:
|
|
91
|
-
response = client.post(f"{self.network}/register", json={"handle": f"@{self.handle}", "url": self.url, "mode": mode})
|
|
92
|
-
if response.status_code==200:
|
|
93
|
-
print(f"✦/✧ published 🎉")
|
|
94
|
-
print("")
|
|
95
|
-
else:
|
|
96
|
-
print("✦/✧ failed to register ⚠️") # exit app
|
|
97
|
-
except Exception as e:
|
|
98
|
-
print(f"An error occurred: {e}")
|
|
99
|
-
|
|
100
|
-
def tunnel(self):
|
|
101
|
-
# ssh_command = ['ssh', '-q', '-i', 'tuns', '-o', 'StrictHostKeyChecking=no', '-R', f'{self.handle}-cycls:80:localhost:{self.port}', 'tuns.sh']
|
|
102
|
-
# ssh_command = ['ssh', '-q', '-i', 'key.pub', '-o', 'StrictHostKeyChecking=no', '-R', f'{self.handle}-cycls:80:localhost:{self.port}', 'serveo.net']
|
|
103
|
-
ssh_command = ['ssh', '-q', '-i', key_path, '-o', 'StrictHostKeyChecking=no', '-R', f'{self.handle}-cycls:80:localhost:{self.port}', 'serveo.net']
|
|
104
|
-
try:
|
|
105
|
-
if self.debug:
|
|
106
|
-
process = subprocess.run(ssh_command,stdin=subprocess.DEVNULL) # very tricky! STDIN is what was messing with me
|
|
107
|
-
else:
|
|
108
|
-
process = subprocess.run(ssh_command, stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
|
109
|
-
except Exception as e:
|
|
110
|
-
print(f"An error occurred: {e}") # exit app
|
|
105
|
+
self.url = f"http://{self.subdomain}-cycls.tuns.sh"
|
|
106
|
+
print("✦/✧","development mode")
|
|
107
|
+
# print("✦/✧",f"url {self.url}")
|
|
108
|
+
register(list(self.apps.keys()), self.network, self.url+"/gateway", "dev")
|
|
109
|
+
t2 = asyncio.create_task(run_server(self.server,self.port))
|
|
110
|
+
|
|
111
|
+
t1 = asyncio.create_task(create_ssh_tunnel(f"{self.subdomain}-cycls", self.port))
|
|
112
|
+
await asyncio.gather(t1, t2) if not prod else asyncio.gather(t2)
|
|
111
113
|
|
|
112
114
|
Text = StreamingResponse
|
|
113
115
|
|
cycls/tuns
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
-----BEGIN OPENSSH PRIVATE KEY-----
|
|
2
|
+
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABFwAAAAdzc2gtcn
|
|
3
|
+
NhAAAAAwEAAQAAAQEAxq9z8nrMUnCRBSDhOcUeAZ//dolIg7RQoXM+Yo6aPACuqRMjo70b
|
|
4
|
+
wzXotyIqFRHe5eLntoa5FLj4n/3/uKVjy+f0xwPxquzTRESJehmUNN7WXaXQt2TX7BmMeo
|
|
5
|
+
vxWiQ69qzcQMQx7FNJNKSsA4Ynw9fIg/NDvEAtnYotmcF37finCJzj3OOxAaAB53bAzfY2
|
|
6
|
+
GD0JL+W8bzuMXpyZaqD+33selRNLqWVbcgNrJW6IDtZXvT1gBRsVsycbNrBrwFuhafnLW1
|
|
7
|
+
KAP/ZLLRP4w+BUgJVJVu9PqTfTrAcnDwspduNJqAtYPMbvuoToip1kYwws3wl8hHpsal67
|
|
8
|
+
U5xZeOn+5QAAA9i3Fmc8txZnPAAAAAdzc2gtcnNhAAABAQDGr3PyesxScJEFIOE5xR4Bn/
|
|
9
|
+
92iUiDtFChcz5ijpo8AK6pEyOjvRvDNei3IioVEd7l4ue2hrkUuPif/f+4pWPL5/THA/Gq
|
|
10
|
+
7NNERIl6GZQ03tZdpdC3ZNfsGYx6i/FaJDr2rNxAxDHsU0k0pKwDhifD18iD80O8QC2dii
|
|
11
|
+
2ZwXft+KcInOPc47EBoAHndsDN9jYYPQkv5bxvO4xenJlqoP7fex6VE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QQd1hgm50DY9ssKNcFHd8BkLwGVRbgDfwhPLDektZZqRlbrVsqIBkDurVI764h2v8M
|
|
26
|
+
G/fyU3Xv57Ed1vzHAAAAHm1vaGFtbWVkYWxydWpheWlATW9oYW1tZWRzLUFpcgECAwQ=
|
|
27
|
+
-----END OPENSSH PRIVATE KEY-----
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: cycls
|
|
3
|
-
Version: 0.0.2.
|
|
3
|
+
Version: 0.0.2.13
|
|
4
4
|
Summary: Cycls SDK
|
|
5
5
|
Author: Mohammed Jamal
|
|
6
6
|
Author-email: mj@cycls.com
|
|
@@ -11,12 +11,22 @@ Classifier: Programming Language :: Python :: 3.9
|
|
|
11
11
|
Classifier: Programming Language :: Python :: 3.10
|
|
12
12
|
Classifier: Programming Language :: Python :: 3.11
|
|
13
13
|
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Requires-Dist: asyncssh (>=2.14.2,<3.0.0)
|
|
14
15
|
Requires-Dist: fastapi (>=0.111.0,<0.112.0)
|
|
15
16
|
Requires-Dist: httpx (>=0.27.0,<0.28.0)
|
|
16
17
|
Description-Content-Type: text/markdown
|
|
17
18
|
|
|
18
19
|
</br></br><p align="center"><img src="https://cycls.com/static/assets/favicon.svg" alt="Cycls"></p></br>
|
|
19
20
|
|
|
21
|
+
<div align="center">
|
|
22
|
+
<a href="https://pypi.org/project/cycls/" target="_blank" rel="noopener noreferrer">
|
|
23
|
+
<img loading="lazy" src="https://img.shields.io/pypi/v/cycls.svg" alt="PyPI" class="img_ev3q" style="display: inline;">
|
|
24
|
+
</a>
|
|
25
|
+
<a href="https://discord.gg/BMnaMatDC7" target="_blank" rel="noopener noreferrer">
|
|
26
|
+
<img loading="lazy" src="https://img.shields.io/discord/1175782747164389466" alt="Discord" class="img_ev3q" style="display: inline;">
|
|
27
|
+
</a>
|
|
28
|
+
</div>
|
|
29
|
+
|
|
20
30
|
# cycls.py
|
|
21
31
|
|
|
22
32
|
```sh
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
cycls/__init__.py,sha256=mBBqS9LS550Uqluyxs7VdD1W-9sDkQfwqeX681PNiis,39
|
|
2
|
+
cycls/cycls.py,sha256=L7JGqFarMNlqwbUbEIiUm0Tcf_eIddyRP-PzBdHZ2F0,4036
|
|
3
|
+
cycls/tuns,sha256=CT8olxDKOM0cY6r_bbSGtnWyEmEYFVDVHj9ug3gbYHk,1843
|
|
4
|
+
cycls-0.0.2.13.dist-info/METADATA,sha256=ACeVgl-K9Gn7YIn1g-JbNhOpVF516OxMJ2gOkXrloDU,3399
|
|
5
|
+
cycls-0.0.2.13.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
6
|
+
cycls-0.0.2.13.dist-info/RECORD,,
|
cycls/key.pub
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC022DIsZ11836rKBvsXcd1H7AMbirWyFSZczn3KkwaheLE90DigO/WkYhPMP5XJ9L5MIGM9nemiQhciZdN9f7z9o0xJh72ZI2+tl5Fa77a9r+IsuWbhn8fNGIkzvyYx8zwSTZV/f2nMYr4I7sjTVFVlH2Een6R8RCZpJPe9Q4ph+k2BCp4DeKzCuOrH6t//flm4vZnP8EXXXpSxic0TpbSL+Is7jeRsZdA4/7LrASCxzxnz4e0RCyy61B/TCkOHbSk06SPjoykA9amMMQ3T0OaO72bimiiCbRqEudgX0gNSVTxcRpmPARNJJDk72gAuOwAD3cpvIiW1nPu6Zhgb2VozQhsN+Rmh3ZjlYRvBVsHbwAkGb0iTBrtLA9ghiPLD2oXWdRI6P5XnNvSRyRXcrt59e1w9Z6XmKOmRl94NYciaMqH1qEEVnNCWUZyYKpMWRseL7v95FSNEoIL47+I4OPTF657sxZHlE85Oxei858kS6/b8GUT4yJgCq/PnhjN7UtGYCVRSv6UHGgXGvLMZAtHmbs3RlhEeLsluPvzgsDhmO6XzdKgh/MZIHKMIP/BEU11FT2lh/kB4EP48dqQPJMFNefB1ybEC509RCSdzaDATYIGRi7+FV4B1O15nC3EQTudFJl7io3chsLbkayAbGRInYVUJ0WDA5Et7ekIKRPdfw== m@m
|
cycls-0.0.2.11.dist-info/RECORD
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
cycls/__init__.py,sha256=mBBqS9LS550Uqluyxs7VdD1W-9sDkQfwqeX681PNiis,39
|
|
2
|
-
cycls/cycls.py,sha256=E4ZCIGEw1hsr9SJyQXaGzowjfcj_6mkpmwwBszeyaYk,4322
|
|
3
|
-
cycls/key.pub,sha256=hWHddJ0TceUqDpm2xV4hDuNZKAz_wHpWox1yLaZ-JVw,729
|
|
4
|
-
cycls-0.0.2.11.dist-info/METADATA,sha256=PIue53GBeQkUJo70QcoQbTEB_s-WdMwTbHPtW68s4Oo,2864
|
|
5
|
-
cycls-0.0.2.11.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
6
|
-
cycls-0.0.2.11.dist-info/RECORD,,
|
|
File without changes
|