robyn 0.76.0__cp314-cp314-manylinux_2_17_x86_64.manylinux2014_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.
Files changed (57) hide show
  1. robyn/__init__.py +782 -0
  2. robyn/__main__.py +4 -0
  3. robyn/ai.py +308 -0
  4. robyn/argument_parser.py +129 -0
  5. robyn/authentication.py +96 -0
  6. robyn/cli.py +136 -0
  7. robyn/dependency_injection.py +71 -0
  8. robyn/env_populator.py +35 -0
  9. robyn/events.py +6 -0
  10. robyn/exceptions.py +32 -0
  11. robyn/jsonify.py +13 -0
  12. robyn/logger.py +80 -0
  13. robyn/mcp.py +461 -0
  14. robyn/openapi.py +448 -0
  15. robyn/processpool.py +226 -0
  16. robyn/py.typed +0 -0
  17. robyn/reloader.py +164 -0
  18. robyn/responses.py +208 -0
  19. robyn/robyn.cpython-314-x86_64-linux-gnu.so +0 -0
  20. robyn/robyn.pyi +562 -0
  21. robyn/router.py +426 -0
  22. robyn/scaffold/mongo/Dockerfile +12 -0
  23. robyn/scaffold/mongo/app.py +43 -0
  24. robyn/scaffold/mongo/requirements.txt +2 -0
  25. robyn/scaffold/no-db/Dockerfile +12 -0
  26. robyn/scaffold/no-db/app.py +12 -0
  27. robyn/scaffold/no-db/requirements.txt +1 -0
  28. robyn/scaffold/postgres/Dockerfile +32 -0
  29. robyn/scaffold/postgres/app.py +31 -0
  30. robyn/scaffold/postgres/requirements.txt +3 -0
  31. robyn/scaffold/postgres/supervisord.conf +14 -0
  32. robyn/scaffold/prisma/Dockerfile +15 -0
  33. robyn/scaffold/prisma/app.py +32 -0
  34. robyn/scaffold/prisma/requirements.txt +2 -0
  35. robyn/scaffold/prisma/schema.prisma +13 -0
  36. robyn/scaffold/sqlalchemy/Dockerfile +12 -0
  37. robyn/scaffold/sqlalchemy/__init__.py +0 -0
  38. robyn/scaffold/sqlalchemy/app.py +13 -0
  39. robyn/scaffold/sqlalchemy/models.py +21 -0
  40. robyn/scaffold/sqlalchemy/requirements.txt +2 -0
  41. robyn/scaffold/sqlite/Dockerfile +12 -0
  42. robyn/scaffold/sqlite/app.py +22 -0
  43. robyn/scaffold/sqlite/requirements.txt +1 -0
  44. robyn/scaffold/sqlmodel/Dockerfile +11 -0
  45. robyn/scaffold/sqlmodel/app.py +46 -0
  46. robyn/scaffold/sqlmodel/models.py +10 -0
  47. robyn/scaffold/sqlmodel/requirements.txt +2 -0
  48. robyn/status_codes.py +137 -0
  49. robyn/swagger.html +32 -0
  50. robyn/templating.py +30 -0
  51. robyn/types.py +44 -0
  52. robyn/ws.py +67 -0
  53. robyn-0.76.0.dist-info/METADATA +303 -0
  54. robyn-0.76.0.dist-info/RECORD +57 -0
  55. robyn-0.76.0.dist-info/WHEEL +5 -0
  56. robyn-0.76.0.dist-info/entry_points.txt +3 -0
  57. robyn-0.76.0.dist-info/licenses/LICENSE +25 -0
robyn/robyn.pyi ADDED
@@ -0,0 +1,562 @@
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import dataclass
4
+ from enum import Enum
5
+ from typing import Callable, Optional, Union
6
+
7
+ def get_version() -> str:
8
+ pass
9
+
10
+ class SocketHeld:
11
+ def __init__(self, url: str, port: int):
12
+ pass
13
+ def try_clone(self) -> SocketHeld:
14
+ pass
15
+
16
+ class MiddlewareType(Enum):
17
+ """
18
+ The middleware types supported by Robyn.
19
+
20
+ Attributes:
21
+ BEFORE_REQUEST: str
22
+ AFTER_REQUEST: str
23
+ """
24
+
25
+ BEFORE_REQUEST: str
26
+ AFTER_REQUEST: str
27
+
28
+ class HttpMethod(Enum):
29
+ """
30
+ The HTTP methods supported by Robyn.
31
+
32
+ Attributes:
33
+ GET: str
34
+ POST: str
35
+ PUT: str
36
+ DELETE: str
37
+ PATCH: str
38
+ OPTIONS: str
39
+ HEAD: str
40
+ TRACE: str
41
+ CONNECT: str
42
+ """
43
+
44
+ GET: str
45
+ POST: str
46
+ PUT: str
47
+ DELETE: str
48
+ PATCH: str
49
+ OPTIONS: str
50
+ HEAD: str
51
+ TRACE: str
52
+ CONNECT: str
53
+
54
+ @dataclass
55
+ class FunctionInfo:
56
+ """
57
+ The function info object passed to the route handler.
58
+
59
+ Attributes:
60
+ handler (Callable): The function to be called
61
+ is_async (bool): Whether the function is async or not
62
+ number_of_params (int): The number of parameters the function has
63
+ args (dict): The arguments of the function
64
+ kwargs (dict): The keyword arguments of the function
65
+ """
66
+
67
+ handler: Callable
68
+ is_async: bool
69
+ number_of_params: int
70
+ args: dict
71
+ kwargs: dict
72
+
73
+ @dataclass
74
+ class Url:
75
+ """
76
+ The url object passed to the route handler.
77
+
78
+ Attributes:
79
+ scheme (str): The scheme of the url. e.g. http, https
80
+ host (str): The host of the url. e.g. localhost,
81
+ path (str): The path of the url. e.g. /user
82
+ """
83
+
84
+ scheme: str
85
+ host: str
86
+ path: str
87
+
88
+ @dataclass
89
+ class Identity:
90
+ claims: dict[str, str]
91
+
92
+ class QueryParams:
93
+ """
94
+ The query params object passed to the route handler.
95
+
96
+ Attributes:
97
+ queries (dict[str, list[str]]): The query parameters of the request. e.g. /user?id=123 -> {"id": "123"}
98
+ """
99
+
100
+ def set(self, key: str, value: str) -> None:
101
+ """
102
+ Sets the value of the query parameter with the given key.
103
+ If the key already exists, the value will be appended to the list of values.
104
+
105
+ Args:
106
+ key (str): The key of the query parameter
107
+ value (str): The value of the query parameter
108
+ """
109
+ pass
110
+
111
+ def get(self, key: str, default: Optional[str] = None) -> Optional[str]:
112
+ """
113
+ Gets the last value of the query parameter with the given key.
114
+
115
+ Args:
116
+ key (str): The key of the query parameter
117
+ default (Optional[str]): The default value if the key does not exist
118
+ """
119
+ pass
120
+
121
+ def empty(self) -> bool:
122
+ """
123
+ Returns:
124
+ True if the query params are empty, False otherwise
125
+ """
126
+ pass
127
+
128
+ def contains(self, key: str) -> bool:
129
+ """
130
+ Returns:
131
+ True if the query params contain the key, False otherwise
132
+
133
+ Args:
134
+ key (str): The key of the query parameter
135
+ """
136
+ pass
137
+
138
+ def get_first(self, key: str) -> Optional[str]:
139
+ """
140
+ Gets the first value of the query parameter with the given key.
141
+
142
+ Args:
143
+ key (str): The key of the query parameter
144
+
145
+ """
146
+ pass
147
+
148
+ def get_all(self, key: str) -> Optional[list[str]]:
149
+ """
150
+ Gets all the values of the query parameter with the given key.
151
+
152
+ Args:
153
+ key (str): The key of the query parameter
154
+ """
155
+ pass
156
+
157
+ def extend(self, other: QueryParams) -> None:
158
+ """
159
+ Extends the query params with the other query params.
160
+
161
+ Args:
162
+ other (QueryParams): The other QueryParams object
163
+ """
164
+ pass
165
+
166
+ def to_dict(self) -> dict[str, list[str]]:
167
+ """
168
+ Returns:
169
+ The query params as a dictionary
170
+ """
171
+ pass
172
+
173
+ def __contains__(self, key: str) -> bool:
174
+ pass
175
+
176
+ def __repr__(self) -> str:
177
+ pass
178
+
179
+ @dataclass
180
+ class Cookie:
181
+ """
182
+ A cookie with optional attributes following RFC 6265.
183
+
184
+ Attributes:
185
+ value (str): The cookie value
186
+ path (Optional[str]): Cookie path (e.g. "/")
187
+ domain (Optional[str]): Cookie domain
188
+ max_age (Optional[int]): Max age in seconds
189
+ expires (Optional[str]): Expiry date (deprecated, use max_age instead)
190
+ secure (bool): Only send over HTTPS
191
+ http_only (bool): Not accessible via JavaScript
192
+ same_site (Optional[str]): "Strict", "Lax", or "None" (case-insensitive)
193
+ """
194
+
195
+ value: str
196
+ path: Optional[str] = None
197
+ domain: Optional[str] = None
198
+ max_age: Optional[int] = None
199
+ expires: Optional[str] = None
200
+ secure: bool = False
201
+ http_only: bool = False
202
+ same_site: Optional[str] = None
203
+
204
+ @staticmethod
205
+ def deleted() -> "Cookie":
206
+ """
207
+ Create a cookie configured for deletion (expires immediately with max_age=0).
208
+
209
+ Returns:
210
+ Cookie: A cookie that will be deleted by the browser
211
+ """
212
+ pass
213
+
214
+ class Cookies:
215
+ """A collection of cookies keyed by name."""
216
+
217
+ def __init__(self) -> None:
218
+ pass
219
+
220
+ def set(self, name: str, cookie: Cookie) -> None:
221
+ """
222
+ Sets a cookie with the given name.
223
+
224
+ Args:
225
+ name (str): The name of the cookie
226
+ cookie (Cookie): The cookie object
227
+ """
228
+ pass
229
+
230
+ def get(self, name: str) -> Optional[Cookie]:
231
+ """
232
+ Gets the cookie with the given name.
233
+
234
+ Args:
235
+ name (str): The name of the cookie
236
+ """
237
+ pass
238
+
239
+ def remove(self, name: str) -> None:
240
+ """
241
+ Removes the cookie from the collection (does not delete it from the browser).
242
+
243
+ Args:
244
+ name (str): The name of the cookie
245
+ """
246
+ pass
247
+
248
+ def delete(self, name: str) -> None:
249
+ """
250
+ Mark a cookie for deletion by setting it to expire immediately.
251
+ This sets max_age=0 which tells the browser to delete the cookie.
252
+
253
+ Args:
254
+ name (str): The name of the cookie to delete
255
+ """
256
+ pass
257
+
258
+ def is_empty(self) -> bool:
259
+ """
260
+ Returns:
261
+ True if there are no cookies, False otherwise
262
+ """
263
+ pass
264
+
265
+ def keys(self) -> list[str]:
266
+ """
267
+ Returns:
268
+ A list of all cookie names
269
+ """
270
+ pass
271
+
272
+ def __setitem__(self, name: str, cookie: Cookie) -> None:
273
+ pass
274
+
275
+ def __getitem__(self, name: str) -> Optional[Cookie]:
276
+ pass
277
+
278
+ def __contains__(self, name: str) -> bool:
279
+ pass
280
+
281
+ def __len__(self) -> int:
282
+ pass
283
+
284
+ def __iter__(self) -> "CookiesIter":
285
+ pass
286
+
287
+ def __repr__(self) -> str:
288
+ pass
289
+
290
+ class CookiesIter:
291
+ """Iterator for Cookies collection."""
292
+
293
+ def __iter__(self) -> "CookiesIter":
294
+ pass
295
+
296
+ def __next__(self) -> str:
297
+ pass
298
+
299
+ class Headers:
300
+ def __init__(self, default_headers: Optional[dict]) -> None:
301
+ pass
302
+
303
+ def __getitem__(self, key: str) -> Optional[str]:
304
+ pass
305
+
306
+ def __setitem__(self, key: str, value: str) -> None:
307
+ pass
308
+
309
+ def set(self, key: str, value: str) -> None:
310
+ """
311
+ Sets the value of the header with the given key.
312
+ If the key already exists, the value will be appended to the list of values.
313
+
314
+ Args:
315
+ key (str): The key of the header
316
+ value (str): The value of the header
317
+ """
318
+ pass
319
+
320
+ def get(self, key: str) -> Optional[str]:
321
+ """
322
+ Gets the last value of the header with the given key.
323
+
324
+ Args:
325
+ key (str): The key of the header
326
+ """
327
+ pass
328
+
329
+ def populate_from_dict(self, headers: dict[str, str]) -> None:
330
+ """
331
+ Populates the headers from a dictionary.
332
+
333
+ Args:
334
+ headers (dict[str, str]): The dictionary of headers
335
+ """
336
+ pass
337
+
338
+ def contains(self, key: str) -> bool:
339
+ """
340
+ Returns:
341
+ True if the headers contain the key, False otherwise
342
+
343
+ Args:
344
+ key (str): The key of the header
345
+ """
346
+ pass
347
+
348
+ def append(self, key: str, value: str) -> None:
349
+ """
350
+ Appends the value to the header with the given key.
351
+
352
+ Args:
353
+ key (str): The key of the header
354
+ value (str): The value of the header
355
+ """
356
+ pass
357
+
358
+ def is_empty(self) -> bool:
359
+ """
360
+ Returns:
361
+ True if the headers are empty, False otherwise
362
+ """
363
+ pass
364
+
365
+ @dataclass
366
+ class Request:
367
+ """
368
+ The request object passed to the route handler.
369
+
370
+ Attributes:
371
+ query_params (QueryParams): The query parameters of the request. e.g. /user?id=123 -> {"id": "123"}
372
+ headers Headers: The headers of the request. e.g. Headers({"Content-Type": "application/json"})
373
+ path_params (dict[str, str]): The parameters of the request. e.g. /user/:id -> {"id": "123"}
374
+ body (Union[str, bytes]): The body of the request. If the request is a JSON, it will be a dict.
375
+ method (str): The method of the request. e.g. GET, POST, PUT etc.
376
+ url (Url): The url of the request. e.g. https://localhost/user
377
+ form_data (dict[str, str]): The form data of the request. e.g. {"name": "John"}
378
+ files (dict[str, bytes]): The files of the request. e.g. {"file": b"file"}
379
+ ip_addr (Optional[str]): The IP Address of the client
380
+ identity (Optional[Identity]): The identity of the client
381
+ """
382
+
383
+ query_params: QueryParams
384
+ headers: Headers
385
+ path_params: dict[str, str]
386
+ body: Union[str, bytes]
387
+ method: str
388
+ url: Url
389
+ form_data: dict[str, str]
390
+ files: dict[str, bytes]
391
+ ip_addr: Optional[str]
392
+ identity: Optional[Identity]
393
+
394
+ def json(self) -> dict:
395
+ """
396
+ If the body is a valid JSON this will return the parsed JSON data.
397
+ Otherwise, this will throw a ValueError.
398
+ """
399
+ pass
400
+
401
+ @dataclass
402
+ class Response:
403
+ """
404
+ The response object passed to the route handler.
405
+
406
+ Attributes:
407
+ status_code (int): The status code of the response. e.g. 200, 404, 500 etc.
408
+ response_type (Optional[str]): The response type of the response. e.g. text, json, html, file etc.
409
+ headers (Union[Headers, dict]): The headers of the response or Headers directly. e.g. {"Content-Type": "application/json"}
410
+ description (Union[str, bytes]): The body of the response. If the response is a JSON, it will be a dict.
411
+ file_path (Optional[str]): The file path of the response. e.g. /home/user/file.txt
412
+ cookies (Cookies): The cookies to set in the response.
413
+ """
414
+
415
+ status_code: int
416
+ headers: Union[Headers, dict]
417
+ description: Union[str, bytes]
418
+ response_type: Optional[str] = None
419
+ file_path: Optional[str] = None
420
+ cookies: Cookies = None # Initialized automatically
421
+
422
+ def set_cookie(
423
+ self,
424
+ key: str,
425
+ value: str,
426
+ path: Optional[str] = None,
427
+ domain: Optional[str] = None,
428
+ max_age: Optional[int] = None,
429
+ expires: Optional[str] = None,
430
+ secure: bool = False,
431
+ http_only: bool = False,
432
+ same_site: Optional[str] = None,
433
+ ) -> None:
434
+ """
435
+ Sets a cookie in the response. If a cookie with the same key exists,
436
+ it will be overwritten.
437
+
438
+ Args:
439
+ key (str): The name of the cookie
440
+ value (str): The value of the cookie
441
+ path (Optional[str]): Cookie path (e.g. "/")
442
+ domain (Optional[str]): Cookie domain
443
+ max_age (Optional[int]): Max age in seconds
444
+ expires (Optional[str]): Expiry date (RFC 7231 format)
445
+ secure (bool): Only send over HTTPS
446
+ http_only (bool): Not accessible via JavaScript
447
+ same_site (Optional[str]): "Strict", "Lax", or "None"
448
+ """
449
+ pass
450
+
451
+ class Server:
452
+ """
453
+ The Server object used to create a Robyn server.
454
+
455
+ This object is used to create a Robyn server and add routes, middlewares, etc.
456
+ """
457
+ def __init__(self) -> None:
458
+ pass
459
+ def add_directory(
460
+ self,
461
+ route: str,
462
+ directory_path: str,
463
+ show_files_listing: bool,
464
+ index_file: Optional[str],
465
+ ) -> None:
466
+ pass
467
+ def apply_request_headers(self, headers: Headers) -> None:
468
+ pass
469
+ def apply_response_headers(self, headers: Headers) -> None:
470
+ pass
471
+ def set_response_headers_exclude_paths(self, excluded_response_headers_paths: Optional[list[str]] = None):
472
+ pass
473
+
474
+ def add_route(
475
+ self,
476
+ route_type: HttpMethod,
477
+ route: str,
478
+ function: FunctionInfo,
479
+ is_const: bool,
480
+ ) -> None:
481
+ pass
482
+ def add_global_middleware(self, middleware_type: MiddlewareType, function: FunctionInfo) -> None:
483
+ pass
484
+ def add_middleware_route(
485
+ self,
486
+ middleware_type: MiddlewareType,
487
+ route: str,
488
+ function: FunctionInfo,
489
+ route_type: HttpMethod,
490
+ ) -> None:
491
+ pass
492
+ def add_startup_handler(self, function: FunctionInfo) -> None:
493
+ pass
494
+ def add_shutdown_handler(self, function: FunctionInfo) -> None:
495
+ pass
496
+ def add_web_socket_route(
497
+ self,
498
+ route: str,
499
+ connect_route: FunctionInfo,
500
+ close_route: FunctionInfo,
501
+ message_route: FunctionInfo,
502
+ ) -> None:
503
+ pass
504
+ def start(self, socket: SocketHeld, workers: int, client_timeout: int, keep_alive_timeout: int) -> None:
505
+ pass
506
+
507
+ class WebSocketConnector:
508
+ """
509
+ The WebSocketConnector object passed to the route handler.
510
+
511
+ Attributes:
512
+ id (str): The id of the client
513
+ query_params (QueryParams): The query parameters object
514
+
515
+ async_broadcast (Callable): The function to broadcast a message to all clients
516
+ async_send_to (Callable): The function to send a message to the client
517
+ sync_broadcast (Callable): The function to broadcast a message to all clients
518
+ sync_send_to (Callable): The function to send a message to the client
519
+ """
520
+
521
+ id: str
522
+ query_params: QueryParams
523
+
524
+ async def async_broadcast(self, message: str) -> None:
525
+ """
526
+ Broadcasts a message to all clients.
527
+
528
+ Args:
529
+ message (str): The message to broadcast
530
+ """
531
+ pass
532
+ async def async_send_to(self, sender_id: str, message: str) -> None:
533
+ """
534
+ Sends a message to a specific client.
535
+
536
+ Args:
537
+ sender_id (str): The id of the sender
538
+ message (str): The message to send
539
+ """
540
+ pass
541
+ def sync_broadcast(self, message: str) -> None:
542
+ """
543
+ Broadcasts a message to all clients.
544
+
545
+ Args:
546
+ message (str): The message to broadcast
547
+ """
548
+ pass
549
+ def sync_send_to(self, sender_id: str, message: str) -> None:
550
+ """
551
+ Sends a message to a specific client.
552
+
553
+ Args:
554
+ sender_id (str): The id of the sender
555
+ message (str): The message to send
556
+ """
557
+ pass
558
+ def close(self) -> None:
559
+ """
560
+ Closes the connection.
561
+ """
562
+ pass