cycls 0.0.2.12__tar.gz → 0.0.2.13__tar.gz
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-0.0.2.12 → cycls-0.0.2.13}/PKG-INFO +11 -1
- {cycls-0.0.2.12 → cycls-0.0.2.13}/README.md +9 -0
- cycls-0.0.2.13/cycls/cycls.py +116 -0
- cycls-0.0.2.13/cycls/tuns +27 -0
- {cycls-0.0.2.12 → cycls-0.0.2.13}/pyproject.toml +2 -4
- cycls-0.0.2.12/cycls/cycls.py +0 -116
- cycls-0.0.2.12/cycls/key.pub +0 -1
- {cycls-0.0.2.12 → cycls-0.0.2.13}/cycls/__init__.py +0 -0
|
@@ -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
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
</br></br><p align="center"><img src="https://cycls.com/static/assets/favicon.svg" alt="Cycls"></p></br>
|
|
2
2
|
|
|
3
|
+
<div align="center">
|
|
4
|
+
<a href="https://pypi.org/project/cycls/" target="_blank" rel="noopener noreferrer">
|
|
5
|
+
<img loading="lazy" src="https://img.shields.io/pypi/v/cycls.svg" alt="PyPI" class="img_ev3q" style="display: inline;">
|
|
6
|
+
</a>
|
|
7
|
+
<a href="https://discord.gg/BMnaMatDC7" target="_blank" rel="noopener noreferrer">
|
|
8
|
+
<img loading="lazy" src="https://img.shields.io/discord/1175782747164389466" alt="Discord" class="img_ev3q" style="display: inline;">
|
|
9
|
+
</a>
|
|
10
|
+
</div>
|
|
11
|
+
|
|
3
12
|
# cycls.py
|
|
4
13
|
|
|
5
14
|
```sh
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
from fastapi import FastAPI, Request
|
|
2
|
+
from fastapi.responses import StreamingResponse
|
|
3
|
+
from pydantic import BaseModel
|
|
4
|
+
from typing import List, Dict, Optional
|
|
5
|
+
|
|
6
|
+
from functools import wraps
|
|
7
|
+
import uvicorn, socket, httpx
|
|
8
|
+
import inspect
|
|
9
|
+
|
|
10
|
+
import logging
|
|
11
|
+
logging.basicConfig(level=logging.ERROR)
|
|
12
|
+
|
|
13
|
+
import os
|
|
14
|
+
current_dir = os.path.dirname(os.path.abspath(__file__))
|
|
15
|
+
key_path = os.path.join(current_dir, 'tuns')
|
|
16
|
+
|
|
17
|
+
class Message(BaseModel):
|
|
18
|
+
handle: str
|
|
19
|
+
content: str
|
|
20
|
+
id: str
|
|
21
|
+
history: Optional[List[Dict[str, str]]] = None
|
|
22
|
+
|
|
23
|
+
def find_available_port(start_port):
|
|
24
|
+
port = start_port
|
|
25
|
+
while True:
|
|
26
|
+
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
|
27
|
+
if s.connect_ex(('localhost', port)) != 0:
|
|
28
|
+
return port
|
|
29
|
+
port += 1
|
|
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
|
+
|
|
59
|
+
class Cycls:
|
|
60
|
+
def __init__(self, url="", network="https://cycls.com", port=find_available_port(8001)):
|
|
61
|
+
import uuid
|
|
62
|
+
self.subdomain = str(uuid.uuid4())[:8]
|
|
63
|
+
self.server = FastAPI()
|
|
64
|
+
self.network = network
|
|
65
|
+
self.port = port
|
|
66
|
+
self.url = url
|
|
67
|
+
self.apps = {}
|
|
68
|
+
|
|
69
|
+
def __call__(self, handle):
|
|
70
|
+
def decorator(func):
|
|
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
|
|
80
|
+
return decorator
|
|
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):
|
|
96
|
+
prod=False
|
|
97
|
+
if self.url != "":
|
|
98
|
+
prod=True
|
|
99
|
+
|
|
100
|
+
print(f"✦/✧ serving at port: {self.port}")
|
|
101
|
+
if prod:
|
|
102
|
+
print("✦/✧",f"production mode | url: {self.url}")
|
|
103
|
+
register(list(self.apps.keys()), self.network, self.url+"/gateway", "prod")
|
|
104
|
+
else:
|
|
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)
|
|
113
|
+
|
|
114
|
+
Text = StreamingResponse
|
|
115
|
+
|
|
116
|
+
# poetry publish --build
|
|
@@ -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+KcInOPc47EBoAHndsDN9jYYPQkv5bxvO4xenJlqoP7fex6VE0upZVtyA2sl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Y9ssKNcFHd8BkLwGVRbgDfwhPLDektZZqRlbrVsqIBkDurVI764h2v8M
|
|
26
|
+
G/fyU3Xv57Ed1vzHAAAAHm1vaGFtbWVkYWxydWpheWlATW9oYW1tZWRzLUFpcgECAwQ=
|
|
27
|
+
-----END OPENSSH PRIVATE KEY-----
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
|
-
#name = "cycls-dev"
|
|
3
|
-
#version = "0.0.1.3"
|
|
4
|
-
|
|
5
2
|
name = "cycls"
|
|
6
|
-
version = "0.0.2.
|
|
3
|
+
version = "0.0.2.13"
|
|
7
4
|
|
|
8
5
|
packages = [{ include = "cycls" }]
|
|
9
6
|
description = "Cycls SDK"
|
|
@@ -14,6 +11,7 @@ readme = "README.md"
|
|
|
14
11
|
python = "^3.8"
|
|
15
12
|
fastapi = "^0.111.0"
|
|
16
13
|
httpx = "^0.27.0"
|
|
14
|
+
asyncssh = "^2.14.2"
|
|
17
15
|
|
|
18
16
|
|
|
19
17
|
[build-system]
|
cycls-0.0.2.12/cycls/cycls.py
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
from fastapi import FastAPI, Request
|
|
2
|
-
from fastapi.responses import StreamingResponse, PlainTextResponse
|
|
3
|
-
from pydantic import BaseModel
|
|
4
|
-
|
|
5
|
-
from functools import wraps
|
|
6
|
-
import uvicorn, socket, httpx
|
|
7
|
-
import inspect
|
|
8
|
-
|
|
9
|
-
from concurrent.futures import ThreadPoolExecutor
|
|
10
|
-
import time, subprocess
|
|
11
|
-
|
|
12
|
-
import os
|
|
13
|
-
current_dir = os.path.dirname(os.path.abspath(__file__))
|
|
14
|
-
key_path = os.path.join(current_dir, 'key.pub')
|
|
15
|
-
# print(key_path)
|
|
16
|
-
|
|
17
|
-
from typing import List, Dict, Optional
|
|
18
|
-
class Message(BaseModel):
|
|
19
|
-
handle: str
|
|
20
|
-
content: str
|
|
21
|
-
# history: List[Dict[str, str]] = []
|
|
22
|
-
history: Optional[List[Dict[str, str]]] = None
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
def find_available_port(start_port):
|
|
26
|
-
port = start_port
|
|
27
|
-
while True:
|
|
28
|
-
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
|
29
|
-
if s.connect_ex(('localhost', port)) != 0:
|
|
30
|
-
return port
|
|
31
|
-
port += 1
|
|
32
|
-
|
|
33
|
-
class Cycls:
|
|
34
|
-
def __init__(self,network="https://cycls.com", port=find_available_port(8001),url="",debug=False):
|
|
35
|
-
self.handle = None
|
|
36
|
-
self.server = FastAPI()
|
|
37
|
-
self.network = network
|
|
38
|
-
self.port = port
|
|
39
|
-
self.url = url
|
|
40
|
-
self.debug = debug
|
|
41
|
-
|
|
42
|
-
def __call__(self, handle):
|
|
43
|
-
self.handle = handle
|
|
44
|
-
def decorator(func):
|
|
45
|
-
if inspect.iscoroutinefunction(func):
|
|
46
|
-
@wraps(func)
|
|
47
|
-
async def async_wrapper(*args, **kwargs):
|
|
48
|
-
return await func(*args, **kwargs)
|
|
49
|
-
self.server.post('/main')(async_wrapper)
|
|
50
|
-
self.publish()
|
|
51
|
-
return async_wrapper
|
|
52
|
-
else:
|
|
53
|
-
@wraps(func)
|
|
54
|
-
def sync_wrapper(*args, **kwargs):
|
|
55
|
-
return func(*args, **kwargs)
|
|
56
|
-
self.server.post('/main')(sync_wrapper)
|
|
57
|
-
self.publish()
|
|
58
|
-
return sync_wrapper
|
|
59
|
-
return decorator
|
|
60
|
-
|
|
61
|
-
def publish(self):
|
|
62
|
-
prod=False
|
|
63
|
-
if self.url != "":
|
|
64
|
-
prod=True
|
|
65
|
-
|
|
66
|
-
if self.debug: print("✦/✧ debug = True")
|
|
67
|
-
if prod:
|
|
68
|
-
print("✦/✧","production mode",f"(url: {self.url}, port: {self.port})")
|
|
69
|
-
else:
|
|
70
|
-
print("✦/✧","development mode",f"(port: {self.port})")
|
|
71
|
-
# self.url = f"https://{self.handle}-cycls.tuns.sh"
|
|
72
|
-
self.url = f"https://{self.handle}-cycls.serveo.net"
|
|
73
|
-
|
|
74
|
-
print("")
|
|
75
|
-
print("✦/✧",f"https://cycls.com/@{self.handle}")
|
|
76
|
-
print("")
|
|
77
|
-
|
|
78
|
-
with ThreadPoolExecutor() as executor:
|
|
79
|
-
if not prod:
|
|
80
|
-
self.register('dev')
|
|
81
|
-
executor.submit(self.tunnel)
|
|
82
|
-
else:
|
|
83
|
-
self.register('prod')
|
|
84
|
-
|
|
85
|
-
if self.debug:
|
|
86
|
-
executor.submit(uvicorn.run(self.server, host="127.0.0.1", port=self.port)) # perhaps keep traces?
|
|
87
|
-
else:
|
|
88
|
-
executor.submit(uvicorn.run(self.server, host="127.0.0.1", port=self.port, log_level="critical")) # perhaps keep traces?
|
|
89
|
-
|
|
90
|
-
def register(self, mode):
|
|
91
|
-
try:
|
|
92
|
-
with httpx.Client() as client:
|
|
93
|
-
response = client.post(f"{self.network}/register", json={"handle": f"@{self.handle}", "url": self.url, "mode": mode})
|
|
94
|
-
if response.status_code==200:
|
|
95
|
-
print(f"✦/✧ published 🎉")
|
|
96
|
-
print("")
|
|
97
|
-
else:
|
|
98
|
-
print("✦/✧ failed to register ⚠️") # exit app
|
|
99
|
-
except Exception as e:
|
|
100
|
-
print(f"An error occurred: {e}")
|
|
101
|
-
|
|
102
|
-
def tunnel(self):
|
|
103
|
-
# ssh_command = ['ssh', '-q', '-i', 'tuns', '-o', 'StrictHostKeyChecking=no', '-R', f'{self.handle}-cycls:80:localhost:{self.port}', 'tuns.sh']
|
|
104
|
-
# ssh_command = ['ssh', '-q', '-i', 'key.pub', '-o', 'StrictHostKeyChecking=no', '-R', f'{self.handle}-cycls:80:localhost:{self.port}', 'serveo.net']
|
|
105
|
-
ssh_command = ['ssh', '-q', '-i', key_path, '-o', 'StrictHostKeyChecking=no', '-R', f'{self.handle}-cycls:80:localhost:{self.port}', 'serveo.net']
|
|
106
|
-
try:
|
|
107
|
-
if self.debug:
|
|
108
|
-
process = subprocess.run(ssh_command,stdin=subprocess.DEVNULL) # very tricky! STDIN is what was messing with me
|
|
109
|
-
else:
|
|
110
|
-
process = subprocess.run(ssh_command, stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
|
111
|
-
except Exception as e:
|
|
112
|
-
print(f"An error occurred: {e}") # exit app
|
|
113
|
-
|
|
114
|
-
Text = StreamingResponse
|
|
115
|
-
|
|
116
|
-
# ç
|
cycls-0.0.2.12/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
|
|
File without changes
|