robyn 0.73.0__cp311-cp311-macosx_10_12_x86_64.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.
Potentially problematic release.
This version of robyn might be problematic. Click here for more details.
- robyn/__init__.py +757 -0
- robyn/__main__.py +4 -0
- robyn/ai.py +308 -0
- robyn/argument_parser.py +129 -0
- robyn/authentication.py +96 -0
- robyn/cli.py +136 -0
- robyn/dependency_injection.py +71 -0
- robyn/env_populator.py +35 -0
- robyn/events.py +6 -0
- robyn/exceptions.py +32 -0
- robyn/jsonify.py +13 -0
- robyn/logger.py +80 -0
- robyn/mcp.py +461 -0
- robyn/openapi.py +448 -0
- robyn/processpool.py +226 -0
- robyn/py.typed +0 -0
- robyn/reloader.py +164 -0
- robyn/responses.py +208 -0
- robyn/robyn.cpython-311-darwin.so +0 -0
- robyn/robyn.pyi +421 -0
- robyn/router.py +410 -0
- robyn/scaffold/mongo/Dockerfile +12 -0
- robyn/scaffold/mongo/app.py +43 -0
- robyn/scaffold/mongo/requirements.txt +2 -0
- robyn/scaffold/no-db/Dockerfile +12 -0
- robyn/scaffold/no-db/app.py +12 -0
- robyn/scaffold/no-db/requirements.txt +1 -0
- robyn/scaffold/postgres/Dockerfile +32 -0
- robyn/scaffold/postgres/app.py +31 -0
- robyn/scaffold/postgres/requirements.txt +3 -0
- robyn/scaffold/postgres/supervisord.conf +14 -0
- robyn/scaffold/prisma/Dockerfile +15 -0
- robyn/scaffold/prisma/app.py +32 -0
- robyn/scaffold/prisma/requirements.txt +2 -0
- robyn/scaffold/prisma/schema.prisma +13 -0
- robyn/scaffold/sqlalchemy/Dockerfile +12 -0
- robyn/scaffold/sqlalchemy/__init__.py +0 -0
- robyn/scaffold/sqlalchemy/app.py +13 -0
- robyn/scaffold/sqlalchemy/models.py +21 -0
- robyn/scaffold/sqlalchemy/requirements.txt +2 -0
- robyn/scaffold/sqlite/Dockerfile +12 -0
- robyn/scaffold/sqlite/app.py +22 -0
- robyn/scaffold/sqlite/requirements.txt +1 -0
- robyn/scaffold/sqlmodel/Dockerfile +11 -0
- robyn/scaffold/sqlmodel/app.py +46 -0
- robyn/scaffold/sqlmodel/models.py +10 -0
- robyn/scaffold/sqlmodel/requirements.txt +2 -0
- robyn/status_codes.py +137 -0
- robyn/swagger.html +32 -0
- robyn/templating.py +30 -0
- robyn/types.py +44 -0
- robyn/ws.py +67 -0
- robyn-0.73.0.dist-info/METADATA +32 -0
- robyn-0.73.0.dist-info/RECORD +57 -0
- robyn-0.73.0.dist-info/WHEEL +4 -0
- robyn-0.73.0.dist-info/entry_points.txt +3 -0
- robyn-0.73.0.dist-info/licenses/LICENSE +25 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"""This is Robyn's dependency injection file."""
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class DependencyMap:
|
|
7
|
+
def __init__(self) -> None:
|
|
8
|
+
self.global_dependency_map: dict[str, Any] = {}
|
|
9
|
+
# {'router': {'dependency_name': dependency_class}
|
|
10
|
+
self.router_dependency_map: dict[str, dict[str, Any]] = {}
|
|
11
|
+
|
|
12
|
+
def add_router_dependency(self, router, **kwargs):
|
|
13
|
+
"""Adds a dependency to a route.
|
|
14
|
+
|
|
15
|
+
Args:
|
|
16
|
+
router App Object: The route to add the dependency to.
|
|
17
|
+
kwargs (dict): The dependencies to add to the route.
|
|
18
|
+
"""
|
|
19
|
+
if router not in self.router_dependency_map:
|
|
20
|
+
self.router_dependency_map[router] = {}
|
|
21
|
+
|
|
22
|
+
self.router_dependency_map[router].update(**kwargs)
|
|
23
|
+
|
|
24
|
+
def add_global_dependency(self, **kwargs):
|
|
25
|
+
"""Adds a dependency to all routes.
|
|
26
|
+
|
|
27
|
+
Args:
|
|
28
|
+
kwargs (dict): The dependencies to add to all routes.
|
|
29
|
+
"""
|
|
30
|
+
for name, element in kwargs.items():
|
|
31
|
+
self.global_dependency_map.update({name: element})
|
|
32
|
+
|
|
33
|
+
def get_router_dependencies(self, router):
|
|
34
|
+
"""Gets the dependencies for a specific route.
|
|
35
|
+
|
|
36
|
+
Args:
|
|
37
|
+
router
|
|
38
|
+
|
|
39
|
+
Returns:
|
|
40
|
+
dict: The dependencies for the specified route.
|
|
41
|
+
"""
|
|
42
|
+
return self.router_dependency_map.get(router, {})
|
|
43
|
+
|
|
44
|
+
def get_global_dependencies(self):
|
|
45
|
+
"""Gets the dependencies for a route.
|
|
46
|
+
|
|
47
|
+
Args:
|
|
48
|
+
route (str): The route to get the dependencies for.
|
|
49
|
+
"""
|
|
50
|
+
return self.global_dependency_map
|
|
51
|
+
|
|
52
|
+
def merge_dependencies(self, target_router):
|
|
53
|
+
"""
|
|
54
|
+
Merge dependencies from this DependencyMap into another router's DependencyMap.
|
|
55
|
+
|
|
56
|
+
Args:
|
|
57
|
+
target_router: The router with which to merge dependencies.
|
|
58
|
+
|
|
59
|
+
This method iterates through the dependencies of this DependencyMap and adds any dependencies
|
|
60
|
+
that are not already present in the target router's DependencyMap.
|
|
61
|
+
"""
|
|
62
|
+
for dep_key in self.get_global_dependencies():
|
|
63
|
+
if dep_key in target_router.dependencies.get_global_dependencies():
|
|
64
|
+
continue
|
|
65
|
+
target_router.dependencies.get_global_dependencies()[dep_key] = self.get_global_dependencies()[dep_key]
|
|
66
|
+
|
|
67
|
+
def get_dependency_map(self, router) -> dict:
|
|
68
|
+
return {
|
|
69
|
+
"global_dependencies": self.get_global_dependencies(),
|
|
70
|
+
"router_dependencies": self.get_router_dependencies(router),
|
|
71
|
+
}
|
robyn/env_populator.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
import os
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
logger = logging.getLogger(__name__)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
# parse the configuration file returning a list of tuples (key, value) containing the environment variables
|
|
9
|
+
def parser(config_path=None, project_root=""):
|
|
10
|
+
"""Find robyn.env file in root of the project and parse it"""
|
|
11
|
+
if config_path is None:
|
|
12
|
+
config_path = Path(project_root) / "robyn.env"
|
|
13
|
+
|
|
14
|
+
if config_path.exists():
|
|
15
|
+
with open(config_path, "r") as f:
|
|
16
|
+
for line in f:
|
|
17
|
+
if line.startswith("#"):
|
|
18
|
+
continue
|
|
19
|
+
yield line.strip().split("=")
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
# check for the environment variables set in cli and if not set them
|
|
23
|
+
def load_vars(variables=None, project_root=""):
|
|
24
|
+
"""Main function"""
|
|
25
|
+
|
|
26
|
+
if variables is None:
|
|
27
|
+
variables = parser(project_root=project_root)
|
|
28
|
+
|
|
29
|
+
for var in variables:
|
|
30
|
+
if var[0] in os.environ:
|
|
31
|
+
logger.info(" Variable %s already set", var[0])
|
|
32
|
+
continue
|
|
33
|
+
else:
|
|
34
|
+
os.environ[var[0]] = var[1]
|
|
35
|
+
logger.info(" Variable %s set to %s", var[0], var[1])
|
robyn/events.py
ADDED
robyn/exceptions.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import http
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class HTTPException(Exception):
|
|
5
|
+
def __init__(self, status_code: int, detail: str | None = None) -> None:
|
|
6
|
+
if detail is None:
|
|
7
|
+
detail = http.HTTPStatus(status_code).phrase
|
|
8
|
+
self.status_code = status_code
|
|
9
|
+
self.detail = detail
|
|
10
|
+
|
|
11
|
+
def __str__(self) -> str:
|
|
12
|
+
return f"{self.status_code}: {self.detail}"
|
|
13
|
+
|
|
14
|
+
def __repr__(self) -> str:
|
|
15
|
+
class_name = self.__class__.__name__
|
|
16
|
+
return f"{class_name}(status_code={self.status_code}, detail={self.detail})"
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class WebSocketException(Exception):
|
|
20
|
+
def __init__(self, code: int, reason: str | None = None) -> None:
|
|
21
|
+
self.code = code
|
|
22
|
+
self.reason = reason or ""
|
|
23
|
+
|
|
24
|
+
def __str__(self) -> str:
|
|
25
|
+
return f"{self.code}: {self.reason}"
|
|
26
|
+
|
|
27
|
+
def __repr__(self) -> str:
|
|
28
|
+
class_name = self.__class__.__name__
|
|
29
|
+
return f"{class_name}(code={self.code}, reason={self.reason})"
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
__all__ = ["HTTPException", "WebSocketException"]
|
robyn/jsonify.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import orjson
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def jsonify(input_dict: dict) -> str:
|
|
5
|
+
"""
|
|
6
|
+
This function serializes input dict to a json string
|
|
7
|
+
|
|
8
|
+
Attributes:
|
|
9
|
+
input_dict dict: response of the function
|
|
10
|
+
"""
|
|
11
|
+
output_binary = orjson.dumps(input_dict)
|
|
12
|
+
output_str = output_binary.decode("utf-8")
|
|
13
|
+
return output_str
|
robyn/logger.py
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
from enum import Enum
|
|
3
|
+
from typing import Optional
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Colors(Enum):
|
|
7
|
+
BLUE = "\033[94m"
|
|
8
|
+
CYAN = "\033[96m"
|
|
9
|
+
GREEN = "\033[92m"
|
|
10
|
+
YELLOW = "\033[93m"
|
|
11
|
+
RED = "\033[91m"
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class Logger:
|
|
15
|
+
HEADER = "\033[95m"
|
|
16
|
+
ENDC = "\033[0m"
|
|
17
|
+
BOLD = "\033[1m"
|
|
18
|
+
UNDERLINE = "\033[4m"
|
|
19
|
+
|
|
20
|
+
def __init__(self):
|
|
21
|
+
self.logger = logging.getLogger(__name__)
|
|
22
|
+
|
|
23
|
+
def _format_msg(
|
|
24
|
+
self,
|
|
25
|
+
msg: str,
|
|
26
|
+
color: Optional[Colors],
|
|
27
|
+
bold: bool,
|
|
28
|
+
underline: bool,
|
|
29
|
+
):
|
|
30
|
+
result = msg
|
|
31
|
+
if color is not None:
|
|
32
|
+
result = f"{color.value}{result}{Logger.ENDC}"
|
|
33
|
+
if bold:
|
|
34
|
+
result = f"{Logger.BOLD}{result}"
|
|
35
|
+
if underline:
|
|
36
|
+
result = f"{Logger.UNDERLINE}{result}"
|
|
37
|
+
return result
|
|
38
|
+
|
|
39
|
+
def error(
|
|
40
|
+
self,
|
|
41
|
+
msg: str,
|
|
42
|
+
*args,
|
|
43
|
+
color: Optional[Colors] = Colors.RED,
|
|
44
|
+
bold: bool = False,
|
|
45
|
+
underline: bool = False,
|
|
46
|
+
):
|
|
47
|
+
self.logger.error(self._format_msg(msg, color, bold, underline), *args)
|
|
48
|
+
|
|
49
|
+
def warn(
|
|
50
|
+
self,
|
|
51
|
+
msg: str,
|
|
52
|
+
*args,
|
|
53
|
+
color: Optional[Colors] = Colors.YELLOW,
|
|
54
|
+
bold: bool = False,
|
|
55
|
+
underline: bool = False,
|
|
56
|
+
):
|
|
57
|
+
self.logger.warn(self._format_msg(msg, color, bold, underline), *args)
|
|
58
|
+
|
|
59
|
+
def info(
|
|
60
|
+
self,
|
|
61
|
+
msg: str,
|
|
62
|
+
*args,
|
|
63
|
+
color: Optional[Colors] = Colors.GREEN,
|
|
64
|
+
bold: bool = False,
|
|
65
|
+
underline: bool = False,
|
|
66
|
+
):
|
|
67
|
+
self.logger.info(self._format_msg(msg, color, bold, underline), *args)
|
|
68
|
+
|
|
69
|
+
def debug(
|
|
70
|
+
self,
|
|
71
|
+
msg: str,
|
|
72
|
+
*args,
|
|
73
|
+
color: Colors = Colors.BLUE,
|
|
74
|
+
bold: bool = False,
|
|
75
|
+
underline: bool = False,
|
|
76
|
+
):
|
|
77
|
+
self.logger.debug(self._format_msg(msg, color, bold, underline), *args)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
logger = Logger()
|