@anvil-works/anvil-pyright 0.0.1 → 0.0.2-canary
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.
- package/dist/anvil-typeshed/TODOS.md +70 -0
- package/dist/anvil-typeshed/client/anvil/__init__.pyi +1291 -0
- package/dist/anvil-typeshed/client/anvil/__pycache__/server.cpython-39.pyc +0 -0
- package/dist/anvil-typeshed/client/anvil/email.pyi +152 -0
- package/dist/anvil-typeshed/client/anvil/facebook/__init__.pyi +8 -0
- package/dist/anvil-typeshed/client/anvil/facebook/auth.pyi +30 -0
- package/dist/anvil-typeshed/client/anvil/google/__init__.pyi +11 -0
- package/dist/anvil-typeshed/client/anvil/google/auth.pyi +37 -0
- package/dist/anvil-typeshed/client/anvil/google/drive.pyi +98 -0
- package/dist/anvil-typeshed/client/anvil/google/sheets.pyi +98 -0
- package/dist/anvil-typeshed/client/anvil/http.pyi +66 -0
- package/dist/anvil-typeshed/client/anvil/image.pyi +30 -0
- package/dist/anvil-typeshed/client/anvil/js/__init__.pyi +143 -0
- package/dist/anvil-typeshed/client/anvil/js/window/__init__.pyi +2935 -0
- package/dist/anvil-typeshed/client/anvil/media.pyi +46 -0
- package/dist/anvil-typeshed/client/anvil/microsoft/__init__.pyi +8 -0
- package/dist/anvil-typeshed/client/anvil/microsoft/auth.pyi +34 -0
- package/dist/anvil-typeshed/client/anvil/mpl_util.pyi +29 -0
- package/dist/anvil-typeshed/client/anvil/plotly_templates.pyi +15 -0
- package/dist/anvil-typeshed/client/anvil/saml/__init__.pyi +8 -0
- package/dist/anvil-typeshed/client/anvil/saml/auth.pyi +24 -0
- package/dist/anvil-typeshed/client/anvil/secrets.pyi +22 -0
- package/dist/anvil-typeshed/client/anvil/server.pyi +376 -0
- package/dist/anvil-typeshed/client/anvil/stripe.pyi +23 -0
- package/dist/anvil-typeshed/client/anvil/tables/__init__.pyi +297 -0
- package/dist/anvil-typeshed/client/anvil/tables/query.pyi +88 -0
- package/dist/anvil-typeshed/client/anvil/tz.pyi +92 -0
- package/dist/anvil-typeshed/client/anvil/users/__init__.pyi +191 -0
- package/dist/anvil-typeshed/client/anvil/users/mfa.pyi +76 -0
- package/dist/anvil-typeshed/client/stripe/__init__.pyi +8 -0
- package/dist/anvil-typeshed/client/stripe/checkout.pyi +67 -0
- package/dist/anvil-typeshed/server/anvil/__init__.pyi +148 -0
- package/dist/anvil-typeshed/server/anvil/email.pyi +188 -0
- package/dist/anvil-typeshed/server/anvil/facebook/__init__.pyi +8 -0
- package/dist/anvil-typeshed/server/anvil/facebook/auth.pyi +27 -0
- package/dist/anvil-typeshed/server/anvil/files.pyi +53 -0
- package/dist/anvil-typeshed/server/anvil/google/__init__.pyi +11 -0
- package/dist/anvil-typeshed/server/anvil/google/auth.pyi +31 -0
- package/dist/anvil-typeshed/server/anvil/google/drive.pyi +98 -0
- package/dist/anvil-typeshed/server/anvil/google/mail.pyi +24 -0
- package/dist/anvil-typeshed/server/anvil/google/sheets.pyi +98 -0
- package/dist/anvil-typeshed/server/anvil/http.pyi +66 -0
- package/dist/anvil-typeshed/server/anvil/image.pyi +30 -0
- package/dist/anvil-typeshed/server/anvil/media.pyi +32 -0
- package/dist/anvil-typeshed/server/anvil/microsoft/__init__.pyi +8 -0
- package/dist/anvil-typeshed/server/anvil/microsoft/auth.pyi +31 -0
- package/dist/anvil-typeshed/server/anvil/mpl_util.pyi +29 -0
- package/dist/anvil-typeshed/server/anvil/pdf.pyi +61 -0
- package/dist/anvil-typeshed/server/anvil/plotly_templates.pyi +15 -0
- package/dist/anvil-typeshed/server/anvil/saml/__init__.pyi +8 -0
- package/dist/anvil-typeshed/server/anvil/saml/auth.pyi +21 -0
- package/dist/anvil-typeshed/server/anvil/secrets.pyi +22 -0
- package/dist/anvil-typeshed/server/anvil/server.pyi +470 -0
- package/dist/anvil-typeshed/server/anvil/stripe.pyi +23 -0
- package/dist/anvil-typeshed/server/anvil/tables/__init__.pyi +319 -0
- package/dist/anvil-typeshed/server/anvil/tables/query.pyi +88 -0
- package/dist/anvil-typeshed/server/anvil/tz.pyi +92 -0
- package/dist/anvil-typeshed/server/anvil/users/__init__.pyi +83 -0
- package/dist/anvil-typeshed/server/anvil/users/mfa.pyi +65 -0
- package/dist/anvil-typeshed/server/stripe/__init__.pyi +8 -0
- package/dist/anvil-typeshed/server/stripe/checkout.pyi +9 -0
- package/dist/anvil-typeshed/source/anvil/__init__.pyi +1306 -0
- package/dist/anvil-typeshed/source/anvil/email.pyi +188 -0
- package/dist/anvil-typeshed/source/anvil/facebook/__init__.pyi +4 -0
- package/dist/anvil-typeshed/source/anvil/facebook/auth.pyi +28 -0
- package/dist/anvil-typeshed/source/anvil/files.pyi +50 -0
- package/dist/anvil-typeshed/source/anvil/google/__init__.pyi +7 -0
- package/dist/anvil-typeshed/source/anvil/google/auth.pyi +35 -0
- package/dist/anvil-typeshed/source/anvil/google/drive.pyi +94 -0
- package/dist/anvil-typeshed/source/anvil/google/mail.pyi +21 -0
- package/dist/anvil-typeshed/source/anvil/google/sheets.pyi +94 -0
- package/dist/anvil-typeshed/source/anvil/http.pyi +62 -0
- package/dist/anvil-typeshed/source/anvil/image.pyi +26 -0
- package/dist/anvil-typeshed/source/anvil/js/__init__.pyi +140 -0
- package/dist/anvil-typeshed/source/anvil/js/window/__init__.pyi +2932 -0
- package/dist/anvil-typeshed/source/anvil/media.pyi +62 -0
- package/dist/anvil-typeshed/source/anvil/microsoft/__init__.pyi +4 -0
- package/dist/anvil-typeshed/source/anvil/microsoft/auth.pyi +32 -0
- package/dist/anvil-typeshed/source/anvil/mpl_util.pyi +25 -0
- package/dist/anvil-typeshed/source/anvil/pdf.pyi +58 -0
- package/dist/anvil-typeshed/source/anvil/plotly_templates.pyi +11 -0
- package/dist/anvil-typeshed/source/anvil/saml/__init__.pyi +4 -0
- package/dist/anvil-typeshed/source/anvil/saml/auth.pyi +22 -0
- package/dist/anvil-typeshed/source/anvil/secrets.pyi +18 -0
- package/dist/anvil-typeshed/source/anvil/server.pyi +511 -0
- package/dist/anvil-typeshed/source/anvil/stripe.pyi +19 -0
- package/dist/anvil-typeshed/source/anvil/tables/__init__.pyi +319 -0
- package/dist/anvil-typeshed/source/anvil/tables/query.pyi +84 -0
- package/dist/anvil-typeshed/source/anvil/tz.pyi +88 -0
- package/dist/anvil-typeshed/source/anvil/users/__init__.pyi +196 -0
- package/dist/anvil-typeshed/source/anvil/users/mfa.pyi +74 -0
- package/dist/anvil-typeshed/source/stripe/__init__.pyi +4 -0
- package/dist/anvil-typeshed/source/stripe/checkout.pyi +65 -0
- package/dist/pyright-langserver.js +1 -1
- package/dist/pyright-langserver.js.map +1 -1
- package/dist/pyright.js +1 -1
- package/dist/pyright.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,511 @@
|
|
|
1
|
+
# Type stubs for anvil.server module
|
|
2
|
+
# Generated files: client/anvil/server.pyi, server/anvil/server.pyi
|
|
3
|
+
|
|
4
|
+
from typing import Any, Callable, TypeVar, overload, ParamSpec, Literal
|
|
5
|
+
from contextlib import contextmanager
|
|
6
|
+
|
|
7
|
+
_T = TypeVar("_T")
|
|
8
|
+
_P = ParamSpec("_P")
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
# ============================================================================
|
|
12
|
+
# Exceptions
|
|
13
|
+
# ============================================================================
|
|
14
|
+
|
|
15
|
+
class SerializationError(Exception):
|
|
16
|
+
"""Raised when serialization fails."""
|
|
17
|
+
...
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class AppOfflineError(Exception):
|
|
21
|
+
"""Raised when the app is offline."""
|
|
22
|
+
...
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
# @server-only
|
|
26
|
+
class SessionExpiredError(Exception):
|
|
27
|
+
"""Raised when the session has expired."""
|
|
28
|
+
...
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class UplinkDisconnectedError(Exception):
|
|
32
|
+
"""Raised when the uplink connection is lost."""
|
|
33
|
+
...
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class ExecutionTerminatedError(Exception):
|
|
37
|
+
"""Raised when execution is terminated."""
|
|
38
|
+
...
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class TimeoutError(Exception):
|
|
42
|
+
"""Raised when a server call times out."""
|
|
43
|
+
...
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class InternalError(Exception):
|
|
47
|
+
"""Raised when an internal server error occurs."""
|
|
48
|
+
...
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class RuntimeUnavailableError(Exception):
|
|
52
|
+
"""Raised when the runtime is unavailable."""
|
|
53
|
+
...
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class QuotaExceededError(Exception):
|
|
57
|
+
"""Raised when a quota is exceeded."""
|
|
58
|
+
...
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
class NoServerFunctionError(Exception):
|
|
62
|
+
"""Raised when a server function is not found."""
|
|
63
|
+
...
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
class PermissionDenied(Exception):
|
|
67
|
+
"""Raised when permission is denied."""
|
|
68
|
+
...
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
class InvalidResponseError(Exception):
|
|
72
|
+
"""Raised when an invalid response is received."""
|
|
73
|
+
...
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
class ServiceNotAdded(Exception):
|
|
77
|
+
"""Raised when a required service is not added to the app."""
|
|
78
|
+
...
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
class BackgroundTaskError(Exception):
|
|
82
|
+
"""Raised when a background task encounters an error."""
|
|
83
|
+
...
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
class BackgroundTaskKilled(Exception):
|
|
87
|
+
"""Raised when a background task is killed."""
|
|
88
|
+
...
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
class BackgroundTaskNotFound(Exception):
|
|
92
|
+
"""Raised when a background task is not found."""
|
|
93
|
+
...
|
|
94
|
+
# @end-server-only
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
# ============================================================================
|
|
98
|
+
# Capabilities
|
|
99
|
+
# ============================================================================
|
|
100
|
+
|
|
101
|
+
class Capability:
|
|
102
|
+
"""A Capability represents the ability to perform an action.
|
|
103
|
+
|
|
104
|
+
[Anvil Docs](https://anvil.works/docs/server/capabilities)"""
|
|
105
|
+
|
|
106
|
+
ANY: Any
|
|
107
|
+
"""Sentinel value for unwrap_capability."""
|
|
108
|
+
|
|
109
|
+
scope: list[Any]
|
|
110
|
+
"""A list representing what this capability represents.
|
|
111
|
+
|
|
112
|
+
It can be extended by calling narrow(), but not shortened.
|
|
113
|
+
Eg: ['my_resource', 42, 'foo']"""
|
|
114
|
+
|
|
115
|
+
is_valid: bool
|
|
116
|
+
"""True if this Capability is still valid; False if it has been invalidated."""
|
|
117
|
+
|
|
118
|
+
def narrow(self, additional_scope: Any) -> "Capability":
|
|
119
|
+
"""Return a new capability that is narrower than this one.
|
|
120
|
+
|
|
121
|
+
Appends additional scope element(s) to it."""
|
|
122
|
+
...
|
|
123
|
+
|
|
124
|
+
def set_update_handler(
|
|
125
|
+
self,
|
|
126
|
+
apply_update: Callable[..., Any],
|
|
127
|
+
get_update: Callable[..., Any] | None = None,
|
|
128
|
+
) -> None:
|
|
129
|
+
"""Set a handler for what happens when an update is sent to this capability.
|
|
130
|
+
|
|
131
|
+
Optionally provide a function for aggregating updates."""
|
|
132
|
+
...
|
|
133
|
+
|
|
134
|
+
def send_update(self, update: Any) -> None:
|
|
135
|
+
"""Send an update to the update handler for this capability."""
|
|
136
|
+
...
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def unwrap_capability(capability: Capability, scope_pattern: list[Any]) -> list[Any]:
|
|
140
|
+
"""Check that the first argument is a valid Capability and its scope matches the pattern.
|
|
141
|
+
|
|
142
|
+
To match, the scope must:
|
|
143
|
+
- Be at least as broad as the pattern (ie the same length or shorter)
|
|
144
|
+
- Contain the same values in the same position as the pattern - unless that
|
|
145
|
+
position in the pattern is Capability.ANY, which matches any value
|
|
146
|
+
|
|
147
|
+
Returns a list of matched scope elements, of the same length as the pattern."""
|
|
148
|
+
...
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
# ============================================================================
|
|
152
|
+
# Call Context
|
|
153
|
+
# ============================================================================
|
|
154
|
+
|
|
155
|
+
class _ClientInfo:
|
|
156
|
+
"""Information about the client that initiated the current session."""
|
|
157
|
+
|
|
158
|
+
type: str
|
|
159
|
+
"""The type of client (e.g., 'browser', 'uplink')."""
|
|
160
|
+
|
|
161
|
+
ip: str | None
|
|
162
|
+
"""The IP address of the client."""
|
|
163
|
+
|
|
164
|
+
location: "_Location | None"
|
|
165
|
+
"""The location of the client, if available."""
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
class _Location:
|
|
169
|
+
"""Geographic location information."""
|
|
170
|
+
|
|
171
|
+
city: str | None
|
|
172
|
+
country: str | None
|
|
173
|
+
latitude: float | None
|
|
174
|
+
longitude: float | None
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
class _StackFrame:
|
|
178
|
+
"""Information about a call stack frame."""
|
|
179
|
+
|
|
180
|
+
type: str
|
|
181
|
+
"""The execution environment type."""
|
|
182
|
+
|
|
183
|
+
is_trusted: bool
|
|
184
|
+
"""Whether this call is from trusted (server-side) code."""
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
class CallContext:
|
|
188
|
+
"""Contains information about what triggered the currently running code."""
|
|
189
|
+
|
|
190
|
+
client: _ClientInfo
|
|
191
|
+
"""An object that describes the client that initiated the current session."""
|
|
192
|
+
|
|
193
|
+
type: str
|
|
194
|
+
"""The execution environment this code is running in.
|
|
195
|
+
|
|
196
|
+
May be 'browser', 'server_module' or 'uplink'."""
|
|
197
|
+
|
|
198
|
+
remote_caller: _StackFrame | None
|
|
199
|
+
"""An object describing the code that called this @anvil.server.callable function."""
|
|
200
|
+
|
|
201
|
+
background_task_id: str | None
|
|
202
|
+
"""The ID of the currently running background task, if there is one."""
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
context: CallContext
|
|
206
|
+
"""Contains information about what triggered the currently running code."""
|
|
207
|
+
|
|
208
|
+
# Call a server function
|
|
209
|
+
def call(fn_name: str, /, *args: Any, **kwargs: Any) -> Any:
|
|
210
|
+
"""Call a server function by name.
|
|
211
|
+
|
|
212
|
+
[Anvil Docs](https://anvil.works/docs/server)"""
|
|
213
|
+
...
|
|
214
|
+
|
|
215
|
+
def call_s(fn_name: str, /, *args: Any, **kwargs: Any) -> Any:
|
|
216
|
+
"""Call a server function by name without showing a loading indicator.
|
|
217
|
+
|
|
218
|
+
[Anvil Docs](https://anvil.works/docs/server)"""
|
|
219
|
+
...
|
|
220
|
+
|
|
221
|
+
# @server-only
|
|
222
|
+
# Callable decorator (server-only - marks functions as callable from client code)
|
|
223
|
+
@overload
|
|
224
|
+
def callable(fn: Callable[_P, _T]) -> Callable[_P, _T]: ...
|
|
225
|
+
@overload
|
|
226
|
+
def callable(*, name: str | None = None, require_user: bool = False) -> Callable[[Callable[_P, _T]], Callable[_P, _T]]: ...
|
|
227
|
+
def callable(fn: Callable[_P, _T] | None = ..., *, name: str | None = None, require_user: bool = False) -> Callable[_P, _T] | Callable[[Callable[_P, _T]], Callable[_P, _T]]:
|
|
228
|
+
"""Mark a function as callable from client code.
|
|
229
|
+
|
|
230
|
+
[Anvil Docs](https://anvil.works/docs/server/server-modules)"""
|
|
231
|
+
...
|
|
232
|
+
# @end-server-only
|
|
233
|
+
|
|
234
|
+
# Server method decorator (for methods in portable classes)
|
|
235
|
+
@overload
|
|
236
|
+
def server_method(fn: Callable[_P, _T]) -> Callable[_P, _T]: ...
|
|
237
|
+
@overload
|
|
238
|
+
def server_method(*, require_user: bool | Callable[..., bool] | None = None) -> Callable[[Callable[_P, _T]], Callable[_P, _T]]: ...
|
|
239
|
+
def server_method(
|
|
240
|
+
fn: Callable[_P, _T] | None = ...,
|
|
241
|
+
*,
|
|
242
|
+
require_user: bool | Callable[..., bool] | None = None
|
|
243
|
+
) -> Callable[_P, _T] | Callable[[Callable[_P, _T]], Callable[_P, _T]]:
|
|
244
|
+
"""Mark a method in a portable class as callable from client code.
|
|
245
|
+
|
|
246
|
+
Methods decorated with @anvil.server.server_method can be called on portable
|
|
247
|
+
class instances from client code, and will execute on the server.
|
|
248
|
+
|
|
249
|
+
[Anvil Docs](https://anvil.works/docs/server/portable-classes#server-methods)"""
|
|
250
|
+
...
|
|
251
|
+
|
|
252
|
+
# Background task decorator
|
|
253
|
+
@overload
|
|
254
|
+
def background_task(fn: Callable[_P, _T]) -> Callable[_P, _T]: ...
|
|
255
|
+
@overload
|
|
256
|
+
def background_task() -> Callable[[Callable[_P, _T]], Callable[_P, _T]]: ...
|
|
257
|
+
def background_task(fn: Callable[_P, _T] | None = None) -> Callable[_P, _T] | Callable[[Callable[_P, _T]], Callable[_P, _T]]:
|
|
258
|
+
"""Mark a function as a background task.
|
|
259
|
+
|
|
260
|
+
[Anvil Docs](https://anvil.works/docs/background-tasks)"""
|
|
261
|
+
...
|
|
262
|
+
|
|
263
|
+
# Launch a background task
|
|
264
|
+
def launch_background_task(task_name: str, /, *args: Any, **kwargs: Any) -> Any:
|
|
265
|
+
"""Launch a background task by name.
|
|
266
|
+
|
|
267
|
+
[Anvil Docs](https://anvil.works/docs/background-tasks)"""
|
|
268
|
+
...
|
|
269
|
+
|
|
270
|
+
# Request context
|
|
271
|
+
class request:
|
|
272
|
+
"""HTTP request context for http_endpoint handlers.
|
|
273
|
+
|
|
274
|
+
[Anvil Docs](https://anvil.works/docs/server/http-endpoints)"""
|
|
275
|
+
method: str
|
|
276
|
+
path: str
|
|
277
|
+
body: bytes
|
|
278
|
+
body_json: Any | None
|
|
279
|
+
remote_address: str
|
|
280
|
+
headers: dict[str, str]
|
|
281
|
+
query_params: dict[str, str]
|
|
282
|
+
form_params: dict[str, str]
|
|
283
|
+
cookies: dict[str, str]
|
|
284
|
+
@staticmethod
|
|
285
|
+
def get_header(name: str) -> str | None: ...
|
|
286
|
+
|
|
287
|
+
# Session handling
|
|
288
|
+
class session:
|
|
289
|
+
"""Server-side session storage.
|
|
290
|
+
|
|
291
|
+
[Anvil Docs](https://anvil.works/docs/server/sessions)"""
|
|
292
|
+
@staticmethod
|
|
293
|
+
def get(key: str, default: Any = None) -> Any: ...
|
|
294
|
+
@staticmethod
|
|
295
|
+
def set(key: str, value: Any) -> None: ...
|
|
296
|
+
@staticmethod
|
|
297
|
+
def clear() -> None: ...
|
|
298
|
+
|
|
299
|
+
# HTTP endpoint decorator
|
|
300
|
+
def http_endpoint(path: str, methods: list[str] | None = None, authenticate_users: bool = False, enable_cors: bool = False, cross_site_session: bool = False) -> Callable[[Callable[_P, _T]], Callable[_P, _T]]:
|
|
301
|
+
"""Decorator to create an HTTP endpoint.
|
|
302
|
+
|
|
303
|
+
[Anvil Docs](https://anvil.works/docs/server/http-endpoints)"""
|
|
304
|
+
...
|
|
305
|
+
|
|
306
|
+
# @server-only
|
|
307
|
+
# Route decorator
|
|
308
|
+
def route(
|
|
309
|
+
path: str,
|
|
310
|
+
*,
|
|
311
|
+
require_credentials: bool = False,
|
|
312
|
+
authenticate_users: bool = False,
|
|
313
|
+
methods: list[str] | None = None,
|
|
314
|
+
enable_cors: bool = False,
|
|
315
|
+
cross_site_session: bool = False,
|
|
316
|
+
) -> Callable[[Callable[_P, _T]], Callable[_P, _T]]:
|
|
317
|
+
"""Decorator to create a server-side route.
|
|
318
|
+
|
|
319
|
+
[Anvil Docs](https://anvil.works/docs/http-apis/creating-http-endpoints)"""
|
|
320
|
+
...
|
|
321
|
+
# @end-server-only
|
|
322
|
+
|
|
323
|
+
# Connect to other servers
|
|
324
|
+
def connect(url: str, /, **kwargs: Any) -> Any:
|
|
325
|
+
"""Connect to an Anvil Uplink server.
|
|
326
|
+
|
|
327
|
+
[Anvil Docs](https://anvil.works/docs/uplink)"""
|
|
328
|
+
...
|
|
329
|
+
|
|
330
|
+
# Portable classes
|
|
331
|
+
def portable_class(cls: type[_T], /) -> type[_T]:
|
|
332
|
+
"""Decorator to make a class portable across client and server.
|
|
333
|
+
|
|
334
|
+
[Anvil Docs](https://anvil.works/docs/server/portable-classes)"""
|
|
335
|
+
...
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
# ============================================================================
|
|
339
|
+
# URL and Origin Functions
|
|
340
|
+
# ============================================================================
|
|
341
|
+
|
|
342
|
+
def get_app_origin(environment_type: Literal["published"] | None = None) -> str:
|
|
343
|
+
"""Returns the root URL for the current app.
|
|
344
|
+
|
|
345
|
+
By default, this function returns the URL for the current environment,
|
|
346
|
+
which might be private or temporary. If you want the URL for the published
|
|
347
|
+
branch, pass 'published' as an argument.
|
|
348
|
+
|
|
349
|
+
[Anvil Docs](https://anvil.works/docs/http-apis/creating-http-endpoints#getting-the-url-for-your-api)"""
|
|
350
|
+
...
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
def get_api_origin(environment_type: Literal["published"] | None = None) -> str:
|
|
354
|
+
"""Returns the root URL of the API for the current app.
|
|
355
|
+
|
|
356
|
+
By default, this function returns the URL for the current environment,
|
|
357
|
+
which might be private or temporary. If you want the URL for the published
|
|
358
|
+
branch, pass 'published' as an argument.
|
|
359
|
+
|
|
360
|
+
[Anvil Docs](https://anvil.works/docs/http-apis/creating-http-endpoints#getting-the-url-for-your-api)"""
|
|
361
|
+
...
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
# ============================================================================
|
|
365
|
+
# Session Functions
|
|
366
|
+
# ============================================================================
|
|
367
|
+
|
|
368
|
+
def get_session_id() -> str | None:
|
|
369
|
+
"""Get the current session ID, if any."""
|
|
370
|
+
...
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
def reset_session() -> None:
|
|
374
|
+
"""Reset the current session."""
|
|
375
|
+
...
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
# ============================================================================
|
|
379
|
+
# Background Tasks
|
|
380
|
+
# ============================================================================
|
|
381
|
+
|
|
382
|
+
class BackgroundTaskState:
|
|
383
|
+
"""Information about a background task."""
|
|
384
|
+
|
|
385
|
+
task_id: str
|
|
386
|
+
"""The ID of the background task."""
|
|
387
|
+
|
|
388
|
+
def get_id(self) -> str:
|
|
389
|
+
"""Get the ID of this background task."""
|
|
390
|
+
...
|
|
391
|
+
|
|
392
|
+
def get_state(self) -> dict[str, Any]:
|
|
393
|
+
"""Get the current state of this background task."""
|
|
394
|
+
...
|
|
395
|
+
|
|
396
|
+
def get_return_value(self) -> Any:
|
|
397
|
+
"""Get the return value of this background task, if completed."""
|
|
398
|
+
...
|
|
399
|
+
|
|
400
|
+
def get_error(self) -> Exception | None:
|
|
401
|
+
"""Get the error from this background task, if it failed."""
|
|
402
|
+
...
|
|
403
|
+
|
|
404
|
+
def is_completed(self) -> bool:
|
|
405
|
+
"""Check if this background task has completed."""
|
|
406
|
+
...
|
|
407
|
+
|
|
408
|
+
def is_running(self) -> bool:
|
|
409
|
+
"""Check if this background task is still running."""
|
|
410
|
+
...
|
|
411
|
+
|
|
412
|
+
def kill(self) -> None:
|
|
413
|
+
"""Kill this background task."""
|
|
414
|
+
...
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
def get_background_task(id: str, /) -> BackgroundTaskState:
|
|
418
|
+
"""Returns the Task object of a background task from its id.
|
|
419
|
+
|
|
420
|
+
You can get the task id from task.get_id().
|
|
421
|
+
|
|
422
|
+
[Anvil Docs](https://anvil.works/docs/background-tasks/communicating-back)"""
|
|
423
|
+
...
|
|
424
|
+
|
|
425
|
+
|
|
426
|
+
def list_background_tasks(all_environments: bool = False) -> list[BackgroundTaskState]:
|
|
427
|
+
"""Returns a list of all Tasks running in the current environment.
|
|
428
|
+
|
|
429
|
+
If all_environments is True, this function will return all of the app's
|
|
430
|
+
running Tasks regardless of environment.
|
|
431
|
+
|
|
432
|
+
[Anvil Docs](https://anvil.works/docs/background-tasks#list-background-tasks-from-code)"""
|
|
433
|
+
...
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
# @server-only
|
|
437
|
+
def is_app_online() -> bool:
|
|
438
|
+
"""Check if the app is online."""
|
|
439
|
+
...
|
|
440
|
+
# @end-server-only
|
|
441
|
+
|
|
442
|
+
|
|
443
|
+
# @client-only
|
|
444
|
+
# ============================================================================
|
|
445
|
+
# Loading Indicator (client-only)
|
|
446
|
+
# ============================================================================
|
|
447
|
+
|
|
448
|
+
class _NoLoadingIndicator:
|
|
449
|
+
"""Context manager to suppress the loading indicator."""
|
|
450
|
+
|
|
451
|
+
def __enter__(self) -> None: ...
|
|
452
|
+
def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None: ...
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+
no_loading_indicator: _NoLoadingIndicator
|
|
456
|
+
"""Use `with anvil.server.no_loading_indicator:` to suppress the loading indicator when making server calls."""
|
|
457
|
+
|
|
458
|
+
|
|
459
|
+
@contextmanager
|
|
460
|
+
def loading_indicator(
|
|
461
|
+
*,
|
|
462
|
+
component_name: Any | None = None,
|
|
463
|
+
min_height: int | None = None,
|
|
464
|
+
) -> Any:
|
|
465
|
+
"""Create a loading indicator manually.
|
|
466
|
+
|
|
467
|
+
By default, a loading indicator is displayed when your app is retrieving data.
|
|
468
|
+
This context manager allows you to create loading indicators manually.
|
|
469
|
+
|
|
470
|
+
Args:
|
|
471
|
+
component_name: Optionally give the component or container that the loading
|
|
472
|
+
indicator should overlay.
|
|
473
|
+
min_height: Optionally set the minimum height of the loading indicator."""
|
|
474
|
+
...
|
|
475
|
+
# @end-client-only
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
# ============================================================================
|
|
479
|
+
# HTTP Response Classes
|
|
480
|
+
# ============================================================================
|
|
481
|
+
|
|
482
|
+
# @server-only
|
|
483
|
+
class HttpResponse:
|
|
484
|
+
"""An HTTP response object.
|
|
485
|
+
|
|
486
|
+
[Anvil Docs](https://anvil.works/docs/http-apis/creating-http-endpoints)"""
|
|
487
|
+
|
|
488
|
+
def __init__(
|
|
489
|
+
self,
|
|
490
|
+
status: int = 200,
|
|
491
|
+
body: str | bytes = "",
|
|
492
|
+
headers: dict[str, str] | None = None,
|
|
493
|
+
) -> None: ...
|
|
494
|
+
|
|
495
|
+
|
|
496
|
+
class HttpRequest:
|
|
497
|
+
"""An HTTP request object.
|
|
498
|
+
|
|
499
|
+
[Anvil Docs](https://anvil.works/docs/http-apis/creating-http-endpoints)"""
|
|
500
|
+
|
|
501
|
+
method: str
|
|
502
|
+
path: str
|
|
503
|
+
body: bytes
|
|
504
|
+
body_json: Any | None
|
|
505
|
+
headers: dict[str, str]
|
|
506
|
+
query_params: dict[str, str]
|
|
507
|
+
form_params: dict[str, str]
|
|
508
|
+
username: str | None
|
|
509
|
+
password: str | None
|
|
510
|
+
remote_address: str
|
|
511
|
+
# @end-server-only
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Type stubs for anvil.stripe module
|
|
2
|
+
# Generated files: client/anvil/stripe.pyi, server/anvil/stripe.pyi
|
|
3
|
+
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
class Customer:
|
|
7
|
+
"""A Stripe Customer object."""
|
|
8
|
+
|
|
9
|
+
id: str
|
|
10
|
+
email: str
|
|
11
|
+
def __getattr__(self, name: str) -> Any: ...
|
|
12
|
+
|
|
13
|
+
def new_customer(email_address: str, token: str | None = None) -> Customer:
|
|
14
|
+
"""Create a new Stripe Customer record."""
|
|
15
|
+
...
|
|
16
|
+
|
|
17
|
+
def get_customer(customer_id: str, /) -> Customer:
|
|
18
|
+
"""Retrieve a Stripe Customer record by its ID."""
|
|
19
|
+
...
|