App
inherits from _view
's ViewApp
, which is a base C class for defining the main ASGI entry point. More on that later, though. Most C app functions are called through accessing self
inside of an App
instance.
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 |
|
Configuration in view.py is handled by configzen. For information about changing the config or how files are loaded, look at their docs.
Config loading is done by the load_config
function in config.py
. load_config
searches through the possible paths that a configuration could be found (relative to the path
and directory
parameters passed to it).
The possible config filenames are as follows:
view.toml
view.json
view.ini
view.yaml
view_config.py
config.py
load_config
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 |
|
A new App
instance takes in a Config
, which is then used to handle behavior of the app. Upon creation of a new App
instance, several attributes are set.
config
, which is the Config
object passed._manual_routes
is a list containing routes passed to direct app route functions (e.g. App.get
or App.post
). This makes it easier on the end developer, since they don't have to manually load()
their routes.loaded
, which is just whether load()
has been called.running
is whether the app is started._docs
is a dictionary containing auto-docs information.loaded_routes
is a list of all the loaded routes of the app. This is only populated after calling load()
.Routes called directly on the App
instance (e.g. App.get
) are added to the _manual_routes
attribute, which is then added to the loader when App.load()
is called. Direct App
routes are wrappers around things like get()
in routing.py
.
load()
simply chooses one of the loader entry points (load_simple
or load_fs
) based on the config settings. For more information on the loader, look at the loader docs.