hypern 0.3.6__cp310-cp310-win32.whl → 0.3.8__cp310-cp310-win32.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.
- hypern/__init__.py +21 -1
- hypern/application.py +26 -36
- hypern/args_parser.py +0 -26
- hypern/database/sql/__init__.py +24 -1
- hypern/database/sql/field.py +130 -491
- hypern/database/sql/migrate.py +263 -0
- hypern/database/sql/model.py +4 -3
- hypern/database/sql/query.py +2 -2
- hypern/datastructures.py +2 -2
- hypern/hypern.cp310-win32.pyd +0 -0
- hypern/hypern.pyi +4 -9
- hypern/openapi/schemas.py +5 -7
- hypern/routing/route.py +8 -12
- hypern/worker.py +265 -21
- {hypern-0.3.6.dist-info → hypern-0.3.8.dist-info}/METADATA +16 -6
- {hypern-0.3.6.dist-info → hypern-0.3.8.dist-info}/RECORD +18 -18
- {hypern-0.3.6.dist-info → hypern-0.3.8.dist-info}/WHEEL +1 -1
- hypern/ws.py +0 -16
- {hypern-0.3.6.dist-info → hypern-0.3.8.dist-info}/licenses/LICENSE +0 -0
hypern/__init__.py
CHANGED
@@ -1,4 +1,24 @@
|
|
1
|
+
from hypern.logging import logger
|
2
|
+
from hypern.routing import HTTPEndpoint, QueuedHTTPEndpoint, Route
|
3
|
+
from hypern.ws import WebsocketRoute, WebSocketSession
|
4
|
+
|
1
5
|
from .application import Hypern
|
2
6
|
from .hypern import Request, Response
|
7
|
+
from .response import FileResponse, HTMLResponse, JSONResponse, PlainTextResponse, RedirectResponse
|
3
8
|
|
4
|
-
__all__ = [
|
9
|
+
__all__ = [
|
10
|
+
"Hypern",
|
11
|
+
"Request",
|
12
|
+
"Response",
|
13
|
+
"Route",
|
14
|
+
"HTTPEndpoint",
|
15
|
+
"QueuedHTTPEndpoint",
|
16
|
+
"WebsocketRoute",
|
17
|
+
"WebSocketSession",
|
18
|
+
"FileResponse",
|
19
|
+
"HTMLResponse",
|
20
|
+
"JSONResponse",
|
21
|
+
"PlainTextResponse",
|
22
|
+
"RedirectResponse",
|
23
|
+
"logger",
|
24
|
+
]
|
hypern/application.py
CHANGED
@@ -83,6 +83,14 @@ class Hypern:
|
|
83
83
|
"""
|
84
84
|
),
|
85
85
|
] = None,
|
86
|
+
dependencies: Annotated[
|
87
|
+
dict[str, Any] | None,
|
88
|
+
Doc(
|
89
|
+
"""
|
90
|
+
A dictionary of global dependencies that can be accessed by all routes.
|
91
|
+
"""
|
92
|
+
),
|
93
|
+
] = None,
|
86
94
|
title: Annotated[
|
87
95
|
str,
|
88
96
|
Doc(
|
@@ -209,22 +217,6 @@ class Hypern:
|
|
209
217
|
"""
|
210
218
|
),
|
211
219
|
] = None,
|
212
|
-
default_injectables: Annotated[
|
213
|
-
dict[str, Any] | None,
|
214
|
-
Doc(
|
215
|
-
"""
|
216
|
-
A dictionary of default injectables to be passed to all routes.
|
217
|
-
"""
|
218
|
-
),
|
219
|
-
] = None,
|
220
|
-
auto_compression: Annotated[
|
221
|
-
bool,
|
222
|
-
Doc(
|
223
|
-
"""
|
224
|
-
Enable automatic compression of responses.
|
225
|
-
"""
|
226
|
-
),
|
227
|
-
] = False,
|
228
220
|
database_config: Annotated[
|
229
221
|
DatabaseConfig | None,
|
230
222
|
Doc(
|
@@ -239,15 +231,14 @@ class Hypern:
|
|
239
231
|
super().__init__(*args, **kwargs)
|
240
232
|
self.router = Router(path="/")
|
241
233
|
self.websocket_router = WebsocketRouter(path="/")
|
234
|
+
self.dependencies = dependencies or {}
|
242
235
|
self.scheduler = scheduler
|
243
|
-
self.injectables = default_injectables or {}
|
244
236
|
self.middleware_before_request = []
|
245
237
|
self.middleware_after_request = []
|
246
238
|
self.response_headers = {}
|
247
239
|
self.args = ArgsConfig()
|
248
240
|
self.start_up_handler = None
|
249
241
|
self.shutdown_handler = None
|
250
|
-
self.auto_compression = auto_compression
|
251
242
|
self.database_config = database_config
|
252
243
|
self.thread_config = ThreadConfigurator().get_config()
|
253
244
|
|
@@ -255,7 +246,8 @@ class Hypern:
|
|
255
246
|
self.router.extend_route(route(app=self).routes)
|
256
247
|
|
257
248
|
for websocket_route in websockets or []:
|
258
|
-
|
249
|
+
for route in websocket_route.routes:
|
250
|
+
self.websocket_router.add_route(route)
|
259
251
|
|
260
252
|
if openapi_url and docs_url:
|
261
253
|
self.__add_openapi(
|
@@ -313,6 +305,20 @@ class Hypern:
|
|
313
305
|
self.add_route(HTTPMethod.GET, openapi_url, schema)
|
314
306
|
self.add_route(HTTPMethod.GET, docs_url, template_render)
|
315
307
|
|
308
|
+
def inject(self, key: str, value: Any):
|
309
|
+
"""
|
310
|
+
Injects a key-value pair into the injectables dictionary.
|
311
|
+
|
312
|
+
Args:
|
313
|
+
key (str): The key to be added to the injectables dictionary.
|
314
|
+
value (Any): The value to be associated with the key.
|
315
|
+
|
316
|
+
Returns:
|
317
|
+
self: Returns the instance of the class to allow method chaining.
|
318
|
+
"""
|
319
|
+
self.dependencies[key] = value
|
320
|
+
return self
|
321
|
+
|
316
322
|
def add_response_header(self, key: str, value: str):
|
317
323
|
"""
|
318
324
|
Adds a response header to the response headers dictionary.
|
@@ -366,20 +372,6 @@ class Hypern:
|
|
366
372
|
|
367
373
|
return decorator
|
368
374
|
|
369
|
-
def inject(self, key: str, value: Any):
|
370
|
-
"""
|
371
|
-
Injects a key-value pair into the injectables dictionary.
|
372
|
-
|
373
|
-
Args:
|
374
|
-
key (str): The key to be added to the injectables dictionary.
|
375
|
-
value (Any): The value to be associated with the key.
|
376
|
-
|
377
|
-
Returns:
|
378
|
-
self: Returns the instance of the class to allow method chaining.
|
379
|
-
"""
|
380
|
-
self.injectables[key] = value
|
381
|
-
return self
|
382
|
-
|
383
375
|
def add_middleware(self, middleware: Middleware):
|
384
376
|
"""
|
385
377
|
Adds middleware to the application.
|
@@ -429,12 +421,10 @@ class Hypern:
|
|
429
421
|
server = Server()
|
430
422
|
server.set_router(router=self.router)
|
431
423
|
server.set_websocket_router(websocket_router=self.websocket_router)
|
432
|
-
server.
|
424
|
+
server.set_dependencies(dependencies=self.dependencies)
|
433
425
|
server.set_before_hooks(hooks=self.middleware_before_request)
|
434
426
|
server.set_after_hooks(hooks=self.middleware_after_request)
|
435
427
|
server.set_response_headers(headers=self.response_headers)
|
436
|
-
server.set_auto_compression(enabled=self.auto_compression)
|
437
|
-
server.set_mem_pool_capacity(min_capacity=self.args.min_capacity, max_capacity=self.args.max_capacity)
|
438
428
|
|
439
429
|
if self.database_config:
|
440
430
|
server.set_database_config(config=self.database_config)
|
hypern/args_parser.py
CHANGED
@@ -49,35 +49,12 @@ class ArgsConfig:
|
|
49
49
|
action="store_true",
|
50
50
|
help="It restarts the server based on file changes.",
|
51
51
|
)
|
52
|
-
|
53
|
-
parser.add_argument(
|
54
|
-
"--auto-compression",
|
55
|
-
action="store_true",
|
56
|
-
help="It compresses the response automatically.",
|
57
|
-
)
|
58
|
-
|
59
52
|
parser.add_argument(
|
60
53
|
"--auto-workers",
|
61
54
|
action="store_true",
|
62
55
|
help="It sets the number of workers and max-blocking-threads automatically.",
|
63
56
|
)
|
64
57
|
|
65
|
-
parser.add_argument(
|
66
|
-
"--min-capacity",
|
67
|
-
type=int,
|
68
|
-
default=1,
|
69
|
-
required=False,
|
70
|
-
help="Choose the minimum memory pool capacity. [Default: 1]",
|
71
|
-
)
|
72
|
-
|
73
|
-
parser.add_argument(
|
74
|
-
"--max-capacity",
|
75
|
-
type=int,
|
76
|
-
default=100,
|
77
|
-
required=False,
|
78
|
-
help="Choose the maximum memory pool capacity. [Default: 100]",
|
79
|
-
)
|
80
|
-
|
81
58
|
args, _ = parser.parse_known_args()
|
82
59
|
|
83
60
|
self.host = args.host or "127.0.0.1"
|
@@ -86,7 +63,4 @@ class ArgsConfig:
|
|
86
63
|
self.processes = args.processes or 1
|
87
64
|
self.workers = args.workers or 1
|
88
65
|
self.reload = args.reload or False
|
89
|
-
self.auto_compression = args.auto_compression
|
90
66
|
self.auto_workers = args.auto_workers
|
91
|
-
self.min_capacity = args.min_capacity
|
92
|
-
self.max_capacity = args.max_capacity
|
hypern/database/sql/__init__.py
CHANGED
@@ -1,11 +1,34 @@
|
|
1
1
|
# from .context import SqlConfig, DatabaseType
|
2
|
-
from .field import
|
2
|
+
from .field import (
|
3
|
+
CharField,
|
4
|
+
IntegerField,
|
5
|
+
TextField,
|
6
|
+
FloatField,
|
7
|
+
BooleanField,
|
8
|
+
ForeignKeyField,
|
9
|
+
DateTimeField,
|
10
|
+
Field,
|
11
|
+
JSONField,
|
12
|
+
ArrayField,
|
13
|
+
DecimalField,
|
14
|
+
DateField,
|
15
|
+
)
|
3
16
|
from .model import Model
|
4
17
|
from .query import F, Q, QuerySet
|
5
18
|
|
6
19
|
__all__ = [
|
7
20
|
"CharField",
|
8
21
|
"IntegerField",
|
22
|
+
"TextField",
|
23
|
+
"FloatField",
|
24
|
+
"BooleanField",
|
25
|
+
"ForeignKeyField",
|
26
|
+
"DateTimeField",
|
27
|
+
"Field",
|
28
|
+
"JSONField",
|
29
|
+
"ArrayField",
|
30
|
+
"DecimalField",
|
31
|
+
"DateField",
|
9
32
|
"Model",
|
10
33
|
"Q",
|
11
34
|
"F",
|