hypern 0.3.11__cp311-cp311-macosx_11_0_arm64.whl → 0.3.13__cp311-cp311-macosx_11_0_arm64.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 CHANGED
@@ -5,6 +5,9 @@ from hypern.ws import WebsocketRoute, WebSocketSession
5
5
  from .application import Hypern
6
6
  from .hypern import Request, Response
7
7
  from .response import FileResponse, HTMLResponse, JSONResponse, PlainTextResponse, RedirectResponse
8
+ from .hypern import BackgroundTask
9
+ from .hypern import BackgroundTasks
10
+ from .hypern import Scheduler
8
11
 
9
12
  __all__ = [
10
13
  "Hypern",
@@ -21,4 +24,7 @@ __all__ = [
21
24
  "PlainTextResponse",
22
25
  "RedirectResponse",
23
26
  "logger",
27
+ "BackgroundTask",
28
+ "BackgroundTasks",
29
+ "Scheduler",
24
30
  ]
hypern/application.py CHANGED
@@ -10,8 +10,9 @@ import psutil
10
10
  from typing_extensions import Annotated, Doc
11
11
 
12
12
  from hypern.args_parser import ArgsConfig
13
- from hypern.datastructures import Contact, HTTPMethod, Info, License
14
- from hypern.hypern import DatabaseConfig, FunctionInfo, MiddlewareConfig, Router, Server, WebsocketRouter
13
+ from hypern.datastructures import Contact, Info, License
14
+ from hypern.enum import HTTPMethod
15
+ from hypern.hypern import DatabaseConfig, FunctionInfo, MiddlewareConfig, Router, Server, WebsocketRouter, Scheduler
15
16
  from hypern.hypern import Route as InternalRoute
16
17
  from hypern.logging import logger
17
18
  from hypern.middleware import Middleware
@@ -19,7 +20,6 @@ from hypern.openapi import SchemaGenerator, SwaggerUI
19
20
  from hypern.processpool import run_processes
20
21
  from hypern.response import HTMLResponse, JSONResponse
21
22
  from hypern.routing import Route
22
- from hypern.scheduler import Scheduler
23
23
  from hypern.ws import WebsocketRoute
24
24
 
25
25
  AppType = TypeVar("AppType", bound="Hypern")
@@ -243,7 +243,7 @@ class Hypern:
243
243
  self.thread_config = ThreadConfigurator().get_config()
244
244
 
245
245
  for route in routes or []:
246
- self.router.extend_route(route(app=self).routes)
246
+ self.router.extend_route(route())
247
247
 
248
248
  for websocket_route in websockets or []:
249
249
  for route in websocket_route.routes:
@@ -438,6 +438,7 @@ class Hypern:
438
438
  self.args.max_blocking_threads = self.thread_config.max_blocking_threads
439
439
 
440
440
  if self.args.http2:
441
+ logger.info("HTTP/2 enabled")
441
442
  server.enable_http2()
442
443
 
443
444
  run_processes(
hypern/datastructures.py CHANGED
@@ -1,5 +1,4 @@
1
1
  from typing import Optional
2
- from enum import Enum
3
2
  from pydantic import BaseModel, AnyUrl
4
3
 
5
4
 
@@ -26,15 +25,3 @@ class Info(BaseModelWithConfig):
26
25
  contact: Optional[Contact] = None
27
26
  license: Optional[License] = None
28
27
  version: str
29
-
30
-
31
- class HTTPMethod(Enum):
32
- GET = "GET"
33
- POST = "POST"
34
- PUT = "PUT"
35
- DELETE = "DELETE"
36
- PATCH = "PATCH"
37
- OPTIONS = "OPTIONS"
38
- HEAD = "HEAD"
39
- TRACE = "TRACE"
40
- CONNECT = "CONNECT"
hypern/enum.py CHANGED
@@ -11,3 +11,15 @@ class ErrorCode(Enum):
11
11
  METHOD_NOT_ALLOW = "METHOD_NOT_ALLOW"
12
12
  UNAUTHORIZED = "UNAUTHORIZED"
13
13
  VALIDATION_ERROR = "VALIDATION_ERROR"
14
+
15
+
16
+ class HTTPMethod(Enum):
17
+ GET = "GET"
18
+ POST = "POST"
19
+ PUT = "PUT"
20
+ DELETE = "DELETE"
21
+ PATCH = "PATCH"
22
+ OPTIONS = "OPTIONS"
23
+ HEAD = "HEAD"
24
+ TRACE = "TRACE"
25
+ CONNECT = "CONNECT"
Binary file
hypern/processpool.py CHANGED
@@ -120,8 +120,6 @@ def initialize_event_loop(max_blocking_threads: int = 100) -> asyncio.AbstractEv
120
120
  loop = uvloop.new_event_loop()
121
121
  asyncio.set_event_loop(loop)
122
122
 
123
- loop.slow_callback_duration = 0.1 # Log warnings for slow callbacks
124
- loop.set_debug(False) # Disable debug mode
125
123
  return loop
126
124
 
127
125
 
@@ -2,12 +2,10 @@ from __future__ import annotations
2
2
 
3
3
  import typing
4
4
  from urllib.parse import quote
5
- from hypern.hypern import Response as InternalResponse, Header
5
+ from hypern.hypern import Response as InternalResponse, Header, BackgroundTask, BackgroundTasks
6
6
  import orjson
7
7
  import msgpack
8
8
 
9
- from hypern.background import BackgroundTask, BackgroundTasks
10
-
11
9
 
12
10
  class BaseResponse:
13
11
  media_type = None
hypern/routing/parser.py CHANGED
@@ -36,7 +36,7 @@ class ParamParser:
36
36
  return {k: v[0] for k, v in query_params.items()}
37
37
 
38
38
  def _parse_path_params(self) -> dict:
39
- return lambda: dict(self.request.path_params.items())
39
+ return dict(self.request.path_params.items())
40
40
 
41
41
  def _parse_form_data(self) -> dict:
42
42
  return self.request.json()
hypern/routing/route.py CHANGED
@@ -9,8 +9,10 @@ from pydantic import BaseModel
9
9
  from pydantic.fields import FieldInfo
10
10
 
11
11
  from hypern.auth.authorization import Authorization
12
- from hypern.datastructures import HTTPMethod
13
- from hypern.hypern import FunctionInfo, Request, Router
12
+
13
+ from hypern.enum import HTTPMethod
14
+ from hypern.hypern import FunctionInfo, Request
15
+
14
16
  from hypern.hypern import Route as InternalRoute
15
17
 
16
18
  from .dispatcher import dispatch
@@ -20,6 +22,16 @@ def get_field_type(field):
20
22
  return field.outer_type_
21
23
 
22
24
 
25
+ def join_url_paths(*parts):
26
+ first = parts[0]
27
+ parts = [part.strip("/") for part in parts]
28
+ starts_with_slash = first.startswith("/") if first else False
29
+ joined = "/".join(part for part in parts if part)
30
+ if starts_with_slash:
31
+ joined = "/" + joined
32
+ return joined
33
+
34
+
23
35
  def pydantic_to_swagger(model: type[BaseModel] | dict):
24
36
  if isinstance(model, dict):
25
37
  # Handle the case when a dict is passed instead of a Pydantic model
@@ -216,18 +228,16 @@ class Route:
216
228
  func_info = FunctionInfo(handler=handler, is_async=is_async)
217
229
  return InternalRoute(path=path, function=func_info, method=method)
218
230
 
219
- def __call__(self, app, *args: Any, **kwds: Any) -> Any:
220
- router = Router(self.path)
231
+ def __call__(self, *args: Any, **kwds: Any) -> Any:
232
+ routes = []
221
233
 
222
234
  # Validate handlers
223
235
  if not self.endpoint and not self.functional_handlers:
224
236
  raise ValueError(f"No handler found for route: {self.path}")
225
237
 
226
238
  # Handle functional routes
227
- for route in self.functional_handlers:
228
- router.add_route(route=route)
229
239
  if not self.endpoint:
230
- return router
240
+ return self.functional_handlers
231
241
 
232
242
  # Handle class-based routes
233
243
  for name, func in self.endpoint.__dict__.items():
@@ -235,15 +245,15 @@ class Route:
235
245
  sig = inspect.signature(func)
236
246
  doc = self.swagger_generate(sig, func.__doc__)
237
247
  endpoint_obj = self.endpoint()
238
- route = self.make_internal_route(path="/", handler=endpoint_obj.dispatch, method=name.upper())
248
+ route = self.make_internal_route(path=self.path, handler=endpoint_obj.dispatch, method=name.upper())
239
249
  route.doc = doc
240
- router.add_route(route=route)
250
+ routes.append(route)
241
251
  del endpoint_obj # free up memory
242
- return router
252
+ return routes
243
253
 
244
254
  def add_route(
245
255
  self,
246
- path: str,
256
+ func_path: str,
247
257
  method: str,
248
258
  ) -> Callable:
249
259
  def decorator(func: Callable[..., Any]) -> Callable[..., Any]:
@@ -251,7 +261,7 @@ class Route:
251
261
  return await dispatch(func, request, inject)
252
262
 
253
263
  sig = inspect.signature(func)
254
- route = self.make_internal_route(path=path, handler=functional_wrapper, method=method.upper())
264
+ route = self.make_internal_route(path=join_url_paths(self.path, func_path), handler=functional_wrapper, method=method.upper())
255
265
  route.doc = self.swagger_generate(sig, func.__doc__)
256
266
 
257
267
  self.functional_handlers.append(route)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hypern
3
- Version: 0.3.11
3
+ Version: 0.3.13
4
4
  Classifier: Programming Language :: Rust
5
5
  Classifier: Programming Language :: Python :: Implementation :: CPython
6
6
  Classifier: Programming Language :: Python :: Implementation :: PyPy
@@ -1,6 +1,6 @@
1
- hypern-0.3.11.dist-info/METADATA,sha256=ITw8gsjB2mG8_N0MV--ZF2Fi2pVeFCzAZBGCR0cK80o,4007
2
- hypern-0.3.11.dist-info/WHEEL,sha256=2DV2o9nipXplBZmxLqqNlfrUo6FLhLO4K46OySjBPHk,104
3
- hypern-0.3.11.dist-info/licenses/LICENSE,sha256=VdbaK2hSaaD-LUjtDIlEbeZVmvLGK7BEQvltP3mv-cY,1304
1
+ hypern-0.3.13.dist-info/METADATA,sha256=w5XKaqmlyZArzd-TJhzABRgXo1WLLQfG2QedTkWVl-8,4007
2
+ hypern-0.3.13.dist-info/WHEEL,sha256=2DV2o9nipXplBZmxLqqNlfrUo6FLhLO4K46OySjBPHk,104
3
+ hypern-0.3.13.dist-info/licenses/LICENSE,sha256=VdbaK2hSaaD-LUjtDIlEbeZVmvLGK7BEQvltP3mv-cY,1304
4
4
  hypern/worker.py,sha256=_m0NV-Srn4NGi65UciOOg3t4Bk6wGm0PMG4_1EYi6Zk,9487
5
5
  hypern/middleware/cors.py,sha256=q8Ts_znqApdUJYSJyLlRIbYKxxTQy6WNnJD6Kqbl32I,1759
6
6
  hypern/middleware/security.py,sha256=hPYsilqhF9mRCX7DzOQw4AKh0y5k5FL0cM_zQdb9tiA,7491
@@ -21,12 +21,11 @@ hypern/database/sqlx/model.py,sha256=5liN9IP6cKZhW2SZqQE5ynFNCPVkGL9_xoyPu5PAyjQ
21
21
  hypern/database/sqlx/migrate.py,sha256=gHoZFUPop7OGp_cVic8pKiVnnV1-j2oUAJ9lXVfBBAA,9479
22
22
  hypern/config.py,sha256=Ksn2LnHU0yhtGUjnac9bNjqtxl7IcPKmMdbDfZYm7Jo,7911
23
23
  hypern/response/__init__.py,sha256=9z99BDgASpG404GK8LGkOsXgac0wFwH_cQOTI5Ju-1U,223
24
- hypern/response/response.py,sha256=_UbLlzEfDZvXKHDKOdXFdus-CJXgoNFPmV259cjQz2Q,4729
24
+ hypern/response/response.py,sha256=qa-jmce1PpMezn0GRO6hR5SV0O-y8BspBAm6MdPcreQ,4699
25
25
  hypern/reload.py,sha256=Y2pjHHh8Zv0z-pRkBPLezKiowRblb1ZJ7yI_oE55D4U,1523
26
26
  hypern/auth/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
27
27
  hypern/auth/authorization.py,sha256=b8N_MiBmSJBVR45SsOI2iMGmXYOlNKbsMsrMwXApxtk,30
28
- hypern/background.py,sha256=fN38UlJG6wZf1gOGcvdY-INoD8zJKvGZZOdVYTMjDwg,120
29
- hypern/__init__.py,sha256=IxXU3ev_2KFfceMvBlJBgHeF5_YGYoiDotWJOAiYjh4,615
28
+ hypern/__init__.py,sha256=LsEtm_FRdyAx0Eh51hjPXr_SH9BCyyIzNeBGTN76rRM,778
30
29
  hypern/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
31
30
  hypern/cli/commands.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
32
31
  hypern/openapi/swagger.py,sha256=E5fHYUfFa77zQsCyQGf_vnqJVpl4_KI5qsKFHdgJEdw,61
@@ -38,20 +37,19 @@ hypern/exceptions/common.py,sha256=p9cx3PC6Azn0WAz7jCH02DEoLRLCCvKqNrL-dGhMGSQ,2
38
37
  hypern/exceptions/http.py,sha256=N98kHaQtH4x9EW6Gavrcr-Ll_-HDvsDSaRAX1sNuN4A,3150
39
38
  hypern/exceptions/errors.py,sha256=mt6ZXUGHFZ_FfyP7sZFj4XT6amb5G-1Fa_26rH7BSWc,842
40
39
  hypern/exceptions/base.py,sha256=_tt42Tuy_7oXR-THhJ00lZFsCJMKWbArJyTlF-kcgH4,1955
41
- hypern/application.py,sha256=8dnaBB5zn5H-AccPHO38EWPMun1M3eRyxdF6zXFi1mg,17573
40
+ hypern/application.py,sha256=TlMbzJc3F0ZTymAzA-hOtxXYmEuhGeckB0iIirYBxnI,17595
42
41
  hypern/hypern.pyi,sha256=GSVs2lNIlIU6k8KL2VNOBO8jafEEqzmsmJF6PHNtwAA,8718
43
- hypern/processpool.py,sha256=7DSUMKy0IL6D3822W-XseH6oAU2MCmb-wKRt_80RuZE,3744
42
+ hypern/processpool.py,sha256=N7KFG2ZJm-YlF-QzfUfQsorWsV3yav_HsyDLVWDGEJk,3623
44
43
  hypern/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
45
- hypern/scheduler.py,sha256=nQoWIYMRmKd30g4XwdB072hWTNHvJlLd9S6rLlTFKS0,62
46
44
  hypern/args_parser.py,sha256=hRlZe6VOZUutynVPXzCS8Mpn_Qp36MDDV0hFLNjM5YM,2149
47
45
  hypern/routing/dispatcher.py,sha256=8_JuxyyOMiCqY3WsqcjSzUTpYjIGbvzGtI8j9T-fIkA,2391
48
46
  hypern/routing/queue.py,sha256=Yus-49N4xc7O5S3YYxqL0muFLypu_Zgd0u2SADFh-Uk,7001
49
- hypern/routing/route.py,sha256=juK0eOjmTv1iYYhw3zyLt3uHCB3pT6au64tVcXqCEDc,9976
47
+ hypern/routing/route.py,sha256=Xbws-l5FooG9s_BLgmjqGfgJvapuMhrHYPN8qPb6iag,10196
50
48
  hypern/routing/__init__.py,sha256=FvmUQlSraZ91q9AFGkgj3ELIep1jiKZLBCDrXIVf5DI,157
51
- hypern/routing/parser.py,sha256=VYdQtf9TPe-NSx3J2wCfOZIh1S-iFLf0jdqrY9UPVMQ,3328
49
+ hypern/routing/parser.py,sha256=iYaTAcZCeHgx2QpQSbQ7kQPhDOJQw5DJA6HFk2bqlhM,3320
52
50
  hypern/routing/endpoint.py,sha256=AWLHLQNlSGR8IGU6xM0RP-1kP06OJQzqpbXKSiZEzEo,996
53
- hypern/enum.py,sha256=-StRU0cWboP-y5fNuhB4Q7yMk8Zm_h1Eua9KzOtIyI8,347
54
- hypern/datastructures.py,sha256=SqqYX0iwA0U7R42bYerUjL-gjaA4mu-RwrvVT9biELg,842
51
+ hypern/enum.py,sha256=6sLKuH5fQwc-XpSjf_Z9-lQpi3Id5xqAnl3ihvLF-8Y,551
52
+ hypern/datastructures.py,sha256=q0jWNQBDVcwxIeD9-s9N266rA7aIYn6nAtN4z0Neogk,616
55
53
  hypern/i18n/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
56
54
  hypern/caching/backend.py,sha256=Tj66YSepGUvpXrwC04gSdJzs45IepHA2hNlMtnRVB6c,798
57
55
  hypern/caching/strategies.py,sha256=VU0FpYmIK6rEjjJSwRXPrprYdo0d2u1s9OxB3OAvs3g,7080
@@ -69,5 +67,5 @@ hypern/gateway/gateway.py,sha256=rAZrS9db55tQGUfEfVNIKw6EetBdHAcSXyrC7rLfCZ8,143
69
67
  hypern/gateway/aggregator.py,sha256=Z4LnsDlVDtlPlhsSKu8jCD0UsbztXOLu6UAVtkgJwQk,1100
70
68
  hypern/gateway/proxy.py,sha256=cgMFJ6znUMWRDgPgnRz7HmPT6UUY6Z09-8HAxkCWGgk,2403
71
69
  hypern/gateway/__init__.py,sha256=4wyCK49W_sTBCh0hkTdEli6kdRUFu9UBxncV6EXBxwA,229
72
- hypern/hypern.cpython-311-darwin.so,sha256=w9Uoz9b86JS80QBB2dmyWKUZA6HMjcxFY0JTnE82pjU,8760160
73
- hypern-0.3.11.dist-info/RECORD,,
70
+ hypern/hypern.cpython-311-darwin.so,sha256=qRct_iOE35js3yfnuZpPanB3I3uwjgrzoyqnta7qrQI,8843024
71
+ hypern-0.3.13.dist-info/RECORD,,
hypern/background.py DELETED
@@ -1,4 +0,0 @@
1
- from .hypern import BackgroundTask
2
- from .hypern import BackgroundTasks
3
-
4
- __all__ = ["BackgroundTask", "BackgroundTasks"]
hypern/scheduler.py DELETED
@@ -1,5 +0,0 @@
1
- from .hypern import Scheduler
2
-
3
- __all__ = [
4
- "Scheduler",
5
- ]