App
Bases: ViewApp
Public view.py app object.
src/view/app.py
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 |
|
__init__(config)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
Config
|
Configuration object to be used. Automatically generated by |
required |
src/view/app.py
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 |
|
body(name, *tps, doc=None, default=_NoDefault)
Set a body parameter.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
Name of the parameter. |
required |
tps |
type[V]
|
Types that can be passed to the server. If empty, any is used. |
()
|
doc |
str | None
|
Description of this body parameter. |
None
|
default |
V | None | _NoDefaultType
|
Default value to be used if not supplied. |
_NoDefault
|
src/view/app.py
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 |
|
delete(path, *, doc=None)
Set a DELETE route.
src/view/app.py
333 334 335 |
|
docs(file=None, *, encoding='utf-8', overwrite=True)
Generate documentation for the app.
src/view/app.py
615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 |
|
get(path, *, doc=None)
Set a GET route.
src/view/app.py
325 326 327 |
|
load(routes=None)
Load the app. This is automatically called most of the time and should only be called manually during manual loading.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
routes |
list[Route] | None
|
Routes to load into the app. |
None
|
src/view/app.py
398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 |
|
options(path, *, doc=None)
Set a OPTIONS route.
src/view/app.py
345 346 347 |
|
patch(path, *, doc=None)
Set a PATCH route.
src/view/app.py
337 338 339 |
|
post(path, *, doc=None)
Set a POST route.
src/view/app.py
329 330 331 |
|
put(path, *, doc=None)
Set a PUT route.
src/view/app.py
341 342 343 |
|
query(name, *tps, doc=None, default=_NoDefault)
Set a query parameter.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
Name of the parameter. |
required |
tps |
type[V]
|
Types that can be passed to the server. If empty, any is used. |
()
|
doc |
str | None
|
Description of this query parameter. |
None
|
default |
V | None | _NoDefaultType
|
Default value to be used if not supplied. |
_NoDefault
|
src/view/app.py
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 |
|
run(*, fancy=None)
Run the app.
src/view/app.py
527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 |
|
run_async(loop=None)
Run the app in an event loop.
src/view/app.py
558 559 560 561 562 563 |
|
run_task(loop=None)
Run the app as a task.
src/view/app.py
565 566 567 568 569 570 |
|
run_threaded(*, daemon=True)
Run the app in a thread.
src/view/app.py
552 553 554 555 556 |
|
test()
async
Open the testing context.
src/view/app.py
577 578 579 580 581 582 583 584 585 |
|
get_app(*, address=None)
Get the last app created by new_app
.
src/view/app.py
698 699 700 701 702 703 704 705 706 707 708 |
|
new_app(*, start=False, config_path=None, config_directory=None, post_init=None, app_dealloc=None, store_address=True)
Create a new view app.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start |
bool
|
Should the app be started automatically? (In a new thread) |
False
|
config_path |
Path | str | None
|
Path of the target configuration file |
None
|
config_directory |
Path | str | None
|
Directory path to search for a configuration |
None
|
post_init |
Callback | None
|
Callback to run after the App instance has been created |
None
|
app_dealloc |
Callback | None
|
Callback to run when the App instance is freed from memory |
None
|
store_address |
bool
|
Whether to store the address of the instance to allow use from get_app |
True
|
src/view/app.py
645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 |
|
load_config(path=None, *, directory=None)
Load the configuration file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
Path | None
|
Path to get the configuration from. |
None
|
directory |
Path | None
|
Where to look for the configuration. |
None
|
src/view/config.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
|
AppNotFoundError
Bases: ViewError
, FileNotFoundError
Couldn't find the app from the given path.
src/view/exceptions.py
72 73 74 75 |
|
EnvironmentError
Bases: ViewError
An environment variable is missing.
src/view/exceptions.py
54 55 56 57 |
|
InvalidBodyError
Bases: ViewError
The specified type cannot be used as a view body.
src/view/exceptions.py
60 61 62 63 |
|
LoaderWarning
Bases: ViewWarning
A warning from the loader.
src/view/exceptions.py
30 31 32 33 |
|
MissingLibraryError
Bases: ViewError
A library is not installed.
src/view/exceptions.py
48 49 50 51 |
|
MistakeError
Bases: ViewError
The user made a mistake.
src/view/exceptions.py
66 67 68 69 |
|
NotLoadedWarning
Bases: ViewWarning
load() was never called
src/view/exceptions.py
24 25 26 27 |
|
ViewError
Bases: Exception
Base class for exceptions in view.py
src/view/exceptions.py
36 37 38 39 40 41 42 43 44 45 |
|
ViewWarning
Bases: UserWarning
Base class for all warnings in view.py
src/view/exceptions.py
18 19 20 21 |
|
HTML
Bases: Response[str]
HTML response wrapper.
src/view/response.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
|
Response
Bases: Generic[T]
Wrapper for responses.
src/view/response.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
|
cookie(key, value='', *, max_age=None, expires=None, path=None, domain=None, http_only=False, same_site='lax', partitioned=False, secure=False)
Set a cookie.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key |
str
|
Cookie name. |
required |
value |
str
|
Cookie value. |
''
|
max_age |
int | None
|
Max age of the cookies. |
None
|
expires |
int | datetime | None
|
When the cookie expires. |
None
|
domain |
str | None
|
Domain the cookie is valid at. |
None
|
http_only |
bool
|
Whether the cookie should be HTTP only. |
False
|
same_site |
SameSite
|
SameSite setting for the cookie. |
'lax'
|
partitioned |
bool
|
Whether to tie it to the top level site. |
False
|
secure |
bool
|
Whether the cookie should enforce HTTPS. |
False
|
src/view/response.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
|
Route
dataclass
Bases: Generic[P, T]
, LoadChecker
Standard Route Wrapper
src/view/routing.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
|
debug()
Enable debug mode.
src/view/util.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
|
env(key, *, tp=str)
Get and parse an environment variable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key |
str
|
Environment variable to access. |
required |
tp |
type[EnvConv]
|
Type to convert to. |
str
|
src/view/util.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
|
run(app_or_path)
Run a view app. Should not be used over App.run()
Parameters:
Name | Type | Description | Default |
---|---|---|---|
app_or_path |
str | App
|
App object or path to run. |
required |
src/view/util.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
|
timestamp(tm=_Now)
RFC 1123 Compliant Timestamp
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tm |
datetime | None
|
Date object to create a timestamp for. Now by default. |
_Now
|
src/view/util.py
149 150 151 152 153 154 155 156 |
|