alphaapi 0.3.0b0__cp39-abi3-win_amd64.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.
- alphaapi/__init__.py +180 -0
- alphaapi/_core.pyd +0 -0
- alphaapi/_core.pyi +76 -0
- alphaapi/_debug.py +46 -0
- alphaapi/_helpers.py +63 -0
- alphaapi/app.py +704 -0
- alphaapi/apps.py +126 -0
- alphaapi/auth.py +122 -0
- alphaapi/cli.py +270 -0
- alphaapi/conf.py +227 -0
- alphaapi/cors.py +62 -0
- alphaapi/csrf.py +65 -0
- alphaapi/exceptions.py +74 -0
- alphaapi/http/__init__.py +48 -0
- alphaapi/http/multipart.py +127 -0
- alphaapi/http/request.py +267 -0
- alphaapi/http/response.py +577 -0
- alphaapi/middleware.py +49 -0
- alphaapi/observability.py +152 -0
- alphaapi/openapi.py +205 -0
- alphaapi/params.py +338 -0
- alphaapi/py.typed +0 -0
- alphaapi/scaffold.py +180 -0
- alphaapi/security.py +75 -0
- alphaapi/sessions.py +186 -0
- alphaapi/signed_cookies.py +72 -0
- alphaapi/staticfiles.py +51 -0
- alphaapi/templates.py +91 -0
- alphaapi/testing.py +200 -0
- alphaapi/urls.py +414 -0
- alphaapi/views.py +117 -0
- alphaapi/welcome.py +115 -0
- alphaapi-0.3.0b0.dist-info/METADATA +180 -0
- alphaapi-0.3.0b0.dist-info/RECORD +38 -0
- alphaapi-0.3.0b0.dist-info/WHEEL +4 -0
- alphaapi-0.3.0b0.dist-info/entry_points.txt +2 -0
- alphaapi-0.3.0b0.dist-info/licenses/LICENSE +21 -0
- alphaapi-0.3.0b0.dist-info/sboms/alphaapi.cyclonedx.json +3034 -0
alphaapi/__init__.py
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"""AlphaAPI: a Django-shaped, async-native Python web framework.
|
|
2
|
+
|
|
3
|
+
AlphaAPI keeps Django's project layout and developer ergonomics (settings,
|
|
4
|
+
URLconfs, function and class-based views, middleware, app registry) while using
|
|
5
|
+
an async-first execution model and a Rust HTTP core. It intentionally ships
|
|
6
|
+
**no ORM** and no database layer.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from ._core import Request, Response
|
|
10
|
+
from .app import Application, import_string
|
|
11
|
+
from .apps import AppConfig, AppRegistry, apps
|
|
12
|
+
from .auth import (
|
|
13
|
+
AnonymousUser,
|
|
14
|
+
AuthenticationMiddleware,
|
|
15
|
+
SimpleUser,
|
|
16
|
+
jwt_required,
|
|
17
|
+
login,
|
|
18
|
+
logout,
|
|
19
|
+
)
|
|
20
|
+
from .conf import Settings, settings
|
|
21
|
+
from .conf import package_version as _package_version
|
|
22
|
+
from .cors import CorsMiddleware
|
|
23
|
+
from .csrf import CsrfMiddleware, get_token
|
|
24
|
+
from .exceptions import (
|
|
25
|
+
BadRequest,
|
|
26
|
+
Http404,
|
|
27
|
+
HTTPException,
|
|
28
|
+
PermissionDenied,
|
|
29
|
+
RequestValidationError,
|
|
30
|
+
)
|
|
31
|
+
from .http import (
|
|
32
|
+
FileResponse,
|
|
33
|
+
HttpRequest,
|
|
34
|
+
HttpResponse,
|
|
35
|
+
HttpResponseBadRequest,
|
|
36
|
+
HttpResponseConflict,
|
|
37
|
+
HttpResponseForbidden,
|
|
38
|
+
HttpResponseGatewayTimeout,
|
|
39
|
+
HttpResponseGone,
|
|
40
|
+
HttpResponseNotAllowed,
|
|
41
|
+
HttpResponseNotFound,
|
|
42
|
+
HttpResponseNotModified,
|
|
43
|
+
HttpResponsePermanentRedirect,
|
|
44
|
+
HttpResponseRedirect,
|
|
45
|
+
HttpResponseServerError,
|
|
46
|
+
HttpResponseServiceUnavailable,
|
|
47
|
+
HttpResponseTooManyRequests,
|
|
48
|
+
JsonResponse,
|
|
49
|
+
QueryDict,
|
|
50
|
+
SseResponse,
|
|
51
|
+
StreamingHttpResponse,
|
|
52
|
+
UploadedFile,
|
|
53
|
+
)
|
|
54
|
+
from .middleware import MiddlewareMixin
|
|
55
|
+
from .observability import (
|
|
56
|
+
Metrics,
|
|
57
|
+
MetricsMiddleware,
|
|
58
|
+
RequestIdMiddleware,
|
|
59
|
+
health_response,
|
|
60
|
+
metrics,
|
|
61
|
+
metrics_response,
|
|
62
|
+
readiness_response,
|
|
63
|
+
)
|
|
64
|
+
from .params import Body, Header, Param, Path, Query
|
|
65
|
+
from .security import SecurityMiddleware
|
|
66
|
+
from .sessions import MemorySessionStore, Session, SessionMiddleware, SessionStore
|
|
67
|
+
from .signed_cookies import dumps as dumps_signed
|
|
68
|
+
from .signed_cookies import loads as loads_signed
|
|
69
|
+
from .staticfiles import StaticFiles, static
|
|
70
|
+
from .templates import TemplateEngine, TemplateResponse, render
|
|
71
|
+
from .testing import Client, ClientResponse
|
|
72
|
+
from .urls import (
|
|
73
|
+
NoReverseMatch,
|
|
74
|
+
PathConverter,
|
|
75
|
+
URLPattern,
|
|
76
|
+
URLResolver,
|
|
77
|
+
include,
|
|
78
|
+
path,
|
|
79
|
+
register_converter,
|
|
80
|
+
resolve,
|
|
81
|
+
reverse,
|
|
82
|
+
)
|
|
83
|
+
from .views import RedirectView, View
|
|
84
|
+
|
|
85
|
+
__version__ = _package_version()
|
|
86
|
+
|
|
87
|
+
__all__ = [
|
|
88
|
+
# application / configuration
|
|
89
|
+
"Application",
|
|
90
|
+
"AppConfig",
|
|
91
|
+
"AppRegistry",
|
|
92
|
+
"apps",
|
|
93
|
+
"settings",
|
|
94
|
+
"Settings",
|
|
95
|
+
# URLs
|
|
96
|
+
"path",
|
|
97
|
+
"include",
|
|
98
|
+
"reverse",
|
|
99
|
+
"resolve",
|
|
100
|
+
"register_converter",
|
|
101
|
+
"URLPattern",
|
|
102
|
+
"URLResolver",
|
|
103
|
+
"PathConverter",
|
|
104
|
+
"NoReverseMatch",
|
|
105
|
+
# views
|
|
106
|
+
"View",
|
|
107
|
+
"RedirectView",
|
|
108
|
+
"MiddlewareMixin",
|
|
109
|
+
# parameter markers
|
|
110
|
+
"Param",
|
|
111
|
+
"Query",
|
|
112
|
+
"Header",
|
|
113
|
+
"Body",
|
|
114
|
+
"Path",
|
|
115
|
+
# request / responses
|
|
116
|
+
"Request",
|
|
117
|
+
"Response",
|
|
118
|
+
"HttpRequest",
|
|
119
|
+
"QueryDict",
|
|
120
|
+
"UploadedFile",
|
|
121
|
+
"HttpResponse",
|
|
122
|
+
"JsonResponse",
|
|
123
|
+
"StreamingHttpResponse",
|
|
124
|
+
"SseResponse",
|
|
125
|
+
"FileResponse",
|
|
126
|
+
"HttpResponseRedirect",
|
|
127
|
+
"HttpResponsePermanentRedirect",
|
|
128
|
+
"HttpResponseNotModified",
|
|
129
|
+
"HttpResponseBadRequest",
|
|
130
|
+
"HttpResponseNotFound",
|
|
131
|
+
"HttpResponseForbidden",
|
|
132
|
+
"HttpResponseNotAllowed",
|
|
133
|
+
"HttpResponseServerError",
|
|
134
|
+
"HttpResponseConflict",
|
|
135
|
+
"HttpResponseGone",
|
|
136
|
+
"HttpResponseTooManyRequests",
|
|
137
|
+
"HttpResponseServiceUnavailable",
|
|
138
|
+
"HttpResponseGatewayTimeout",
|
|
139
|
+
# security / middleware
|
|
140
|
+
"SecurityMiddleware",
|
|
141
|
+
"CorsMiddleware",
|
|
142
|
+
"CsrfMiddleware",
|
|
143
|
+
"get_token",
|
|
144
|
+
"SessionMiddleware",
|
|
145
|
+
"Session",
|
|
146
|
+
"SessionStore",
|
|
147
|
+
"MemorySessionStore",
|
|
148
|
+
"AuthenticationMiddleware",
|
|
149
|
+
"jwt_required",
|
|
150
|
+
"AnonymousUser",
|
|
151
|
+
"SimpleUser",
|
|
152
|
+
"login",
|
|
153
|
+
"logout",
|
|
154
|
+
"RequestIdMiddleware",
|
|
155
|
+
"MetricsMiddleware",
|
|
156
|
+
"Metrics",
|
|
157
|
+
"metrics",
|
|
158
|
+
"metrics_response",
|
|
159
|
+
"health_response",
|
|
160
|
+
"readiness_response",
|
|
161
|
+
"dumps_signed",
|
|
162
|
+
"loads_signed",
|
|
163
|
+
# templates / static / testing
|
|
164
|
+
"TemplateEngine",
|
|
165
|
+
"TemplateResponse",
|
|
166
|
+
"render",
|
|
167
|
+
"StaticFiles",
|
|
168
|
+
"static",
|
|
169
|
+
"Client",
|
|
170
|
+
"ClientResponse",
|
|
171
|
+
# exceptions
|
|
172
|
+
"HTTPException",
|
|
173
|
+
"Http404",
|
|
174
|
+
"PermissionDenied",
|
|
175
|
+
"BadRequest",
|
|
176
|
+
"RequestValidationError",
|
|
177
|
+
# misc
|
|
178
|
+
"import_string",
|
|
179
|
+
"__version__",
|
|
180
|
+
]
|
alphaapi/_core.pyd
ADDED
|
Binary file
|
alphaapi/_core.pyi
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
from collections.abc import Awaitable, Callable, Mapping
|
|
2
|
+
from typing import Any
|
|
3
|
+
|
|
4
|
+
class Request:
|
|
5
|
+
method: str
|
|
6
|
+
path: str
|
|
7
|
+
query_string: str
|
|
8
|
+
client: str | None
|
|
9
|
+
headers: dict[str, str]
|
|
10
|
+
params: dict[str, str]
|
|
11
|
+
query_params: dict[str, Any]
|
|
12
|
+
body: bytes
|
|
13
|
+
@property
|
|
14
|
+
def jwt_claims(self) -> dict[str, Any] | None: ...
|
|
15
|
+
def text(self) -> str: ...
|
|
16
|
+
def json(self) -> Any: ...
|
|
17
|
+
def header(self, name: str, default: Any = ...) -> Any: ...
|
|
18
|
+
def query_param(self, name: str, default: Any = ...) -> Any: ...
|
|
19
|
+
|
|
20
|
+
class Response:
|
|
21
|
+
status_code: int
|
|
22
|
+
headers: dict[str, str]
|
|
23
|
+
body: bytes
|
|
24
|
+
media_type: str | None
|
|
25
|
+
def __init__(
|
|
26
|
+
self,
|
|
27
|
+
content: Any = ...,
|
|
28
|
+
status_code: int = ...,
|
|
29
|
+
headers: Mapping[str, str] | list[tuple[str, str]] | None = ...,
|
|
30
|
+
media_type: str | None = ...,
|
|
31
|
+
) -> None: ...
|
|
32
|
+
def header_items(self) -> list[tuple[str, str]]: ...
|
|
33
|
+
def add_header(self, name: str, value: str) -> None: ...
|
|
34
|
+
def set_header(self, name: str, value: str) -> None: ...
|
|
35
|
+
def remove_header(self, name: str) -> bool: ...
|
|
36
|
+
def get_all_headers(self, name: str) -> list[str]: ...
|
|
37
|
+
def clear_headers(self) -> None: ...
|
|
38
|
+
|
|
39
|
+
def dumps(value: Any) -> bytes: ...
|
|
40
|
+
|
|
41
|
+
class JwtPolicy:
|
|
42
|
+
def __init__(
|
|
43
|
+
self, secret: bytes, *, issuer: str | None = ..., audience: str | None = ...
|
|
44
|
+
) -> None: ...
|
|
45
|
+
|
|
46
|
+
class AppCore:
|
|
47
|
+
def __init__(self) -> None: ...
|
|
48
|
+
def add_route(
|
|
49
|
+
self,
|
|
50
|
+
method: str,
|
|
51
|
+
path: str,
|
|
52
|
+
handler: Callable[..., Any],
|
|
53
|
+
spec: dict[str, Any],
|
|
54
|
+
*,
|
|
55
|
+
jwt: JwtPolicy | None = ...,
|
|
56
|
+
) -> None: ...
|
|
57
|
+
def add_exception_handler(
|
|
58
|
+
self,
|
|
59
|
+
exc_type: type[BaseException],
|
|
60
|
+
handler: Callable[..., Any],
|
|
61
|
+
) -> None: ...
|
|
62
|
+
def set_http_exception_type(self, exc_type: type[BaseException]) -> None: ...
|
|
63
|
+
def stop(self) -> None: ...
|
|
64
|
+
def is_running(self) -> bool: ...
|
|
65
|
+
def start_event_loop(self, factory: Callable[[], Any] | None = ...) -> None: ...
|
|
66
|
+
def stop_event_loop(self) -> None: ...
|
|
67
|
+
def run_on_event_loop(self, awaitable: Awaitable[Any]) -> Any: ...
|
|
68
|
+
def run(
|
|
69
|
+
self,
|
|
70
|
+
host: str = ...,
|
|
71
|
+
port: int = ...,
|
|
72
|
+
workers: int | None = ...,
|
|
73
|
+
max_body_size: int | None = ...,
|
|
74
|
+
access_log: bool | None = ...,
|
|
75
|
+
config: Mapping[str, Any] | None = ...,
|
|
76
|
+
) -> None: ...
|
alphaapi/_debug.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"""Development error-page rendering used by the Rust core when DEBUG=True."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import html
|
|
5
|
+
import traceback
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def format_exception(exception: Any) -> str:
|
|
10
|
+
"""Return an HTML traceback for an exception instance."""
|
|
11
|
+
error_type = type(exception)
|
|
12
|
+
lines = traceback.format_exception(
|
|
13
|
+
error_type, exception, getattr(exception, "__traceback__", None)
|
|
14
|
+
)
|
|
15
|
+
traceback_text = "".join(lines)
|
|
16
|
+
return f"""<!doctype html>
|
|
17
|
+
<html>
|
|
18
|
+
<head>
|
|
19
|
+
<meta charset="utf-8">
|
|
20
|
+
<title>{html.escape(error_type.__name__)}</title>
|
|
21
|
+
<style>
|
|
22
|
+
body {{ font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
|
|
23
|
+
margin: 2rem; background: #fff7f7; color: #1f1f1f; }}
|
|
24
|
+
h1 {{ font-family: system-ui, sans-serif; color: #b00020; }}
|
|
25
|
+
pre {{ background: #1f1f1f; color: #f5f5f5; padding: 1rem;
|
|
26
|
+
overflow: auto; border-radius: 6px; }}
|
|
27
|
+
</style>
|
|
28
|
+
</head>
|
|
29
|
+
<body>
|
|
30
|
+
<h1>{html.escape(error_type.__name__)}: {html.escape(str(exception))}</h1>
|
|
31
|
+
<p>The server is running in <strong>DEBUG</strong> mode. Disable it in production.</p>
|
|
32
|
+
<pre>{html.escape(traceback_text)}</pre>
|
|
33
|
+
</body>
|
|
34
|
+
</html>"""
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def format_request_exception(request: Any, exception: Any) -> str:
|
|
38
|
+
page = format_exception(exception)
|
|
39
|
+
summary = (
|
|
40
|
+
f"<p><strong>{html.escape(str(getattr(request, 'method', '')))} "
|
|
41
|
+
f"{html.escape(str(getattr(request, 'path', '')))}</strong></p>"
|
|
42
|
+
)
|
|
43
|
+
return page.replace("<body>", "<body>" + summary, 1)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
__all__ = ["format_exception", "format_request_exception"]
|
alphaapi/_helpers.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"""Helpers used by the Rust core to normalize Python values to JSON."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import dataclasses
|
|
5
|
+
import datetime
|
|
6
|
+
import decimal
|
|
7
|
+
import enum
|
|
8
|
+
import pathlib
|
|
9
|
+
import uuid
|
|
10
|
+
from typing import Any
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def to_builtin(value: Any) -> Any:
|
|
14
|
+
"""Recursively convert ``value`` into JSON-friendly Python builtins."""
|
|
15
|
+
if value is None or isinstance(value, (str, int, float, bool)):
|
|
16
|
+
return value
|
|
17
|
+
|
|
18
|
+
if isinstance(value, bytes):
|
|
19
|
+
return value.decode("utf-8", "replace")
|
|
20
|
+
|
|
21
|
+
if isinstance(value, dict):
|
|
22
|
+
return {key: to_builtin(item) for key, item in value.items()}
|
|
23
|
+
|
|
24
|
+
if isinstance(value, (list, tuple, set, frozenset)):
|
|
25
|
+
return [to_builtin(item) for item in value]
|
|
26
|
+
|
|
27
|
+
model_dump = getattr(value, "model_dump", None)
|
|
28
|
+
if callable(model_dump):
|
|
29
|
+
try:
|
|
30
|
+
dumped = model_dump(mode="json")
|
|
31
|
+
except TypeError:
|
|
32
|
+
dumped = model_dump()
|
|
33
|
+
return to_builtin(dumped)
|
|
34
|
+
|
|
35
|
+
legacy_dict = getattr(value, "dict", None)
|
|
36
|
+
if callable(legacy_dict) and hasattr(value, "__fields__"):
|
|
37
|
+
return to_builtin(legacy_dict())
|
|
38
|
+
|
|
39
|
+
if dataclasses.is_dataclass(value) and not isinstance(value, type):
|
|
40
|
+
return to_builtin(dataclasses.asdict(value))
|
|
41
|
+
|
|
42
|
+
if isinstance(value, enum.Enum):
|
|
43
|
+
return to_builtin(value.value)
|
|
44
|
+
|
|
45
|
+
if isinstance(value, (datetime.datetime, datetime.date, datetime.time)):
|
|
46
|
+
return value.isoformat()
|
|
47
|
+
|
|
48
|
+
if isinstance(value, datetime.timedelta):
|
|
49
|
+
return value.total_seconds()
|
|
50
|
+
|
|
51
|
+
if isinstance(value, uuid.UUID):
|
|
52
|
+
return str(value)
|
|
53
|
+
|
|
54
|
+
if isinstance(value, decimal.Decimal):
|
|
55
|
+
return float(value)
|
|
56
|
+
|
|
57
|
+
if isinstance(value, pathlib.PurePath):
|
|
58
|
+
return str(value)
|
|
59
|
+
|
|
60
|
+
if isinstance(value, BaseException):
|
|
61
|
+
return str(value)
|
|
62
|
+
|
|
63
|
+
return value
|