Project Creation¶
Automatic¶
The View CLI supports automatically creating a project via the view init
command.
Note
Depending on how or where you installed view.py, view
might open vim! If that's the case, run python3 -m view init
, or however your environment works.
Alternatively, you can run view init
with pipx
:
Manually¶
view.py doesn't actually need any big project structure. In fact, you can run an app in just a single Python file, but larger structures like this might be more convenient for big projects. The only real requirement for something to be a view app is that it calls new_app
, but again, more on that later.
Some "hello world" code for manually starting a view project would look like this:
Structure¶
First, in any view project, you need a file to contain your app. By default, view expects it to be in app.py
under a variable called app
. Again, you can change this via the app_path
setting. You're also going to want an app.run()
(assuming you named your App
instance app
), but more on that later.
view.app.new_app(*, start: bool = False, config_path: Path | str | None = None, config_directory: Path | str | None = None, post_init: Callback | None = None, app_dealloc: Callback | None = None, store_address: bool = True, config: Config | None = None, error_class: type[Error] = Error) -> App
¶
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
|
config |
Config | None
|
Raw |
None
|
error_class |
type[Error]
|
Class to be recognized as the view.py HTTP error object. |
Error
|
Generally, you're going to want one of the configuration files talked about earlier, but if you're against configuration files that's OK, view.py will work just fine without it. If you choose to use something other than manual routing, you want a routes
directory (unless you changed the loader_path
setting).
For mobility purposes, you may want to add a pyproject.toml
that contains the dependencies for your project, in case you need to run your project on a different system.