Skip to content

Creating a Project


The View CLI supports automatically creating a project via the view init command.

$ view init

Alternatively, you can run view init with pipx:

$ pipx run view-py init

Manually 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:

from view import new_app

app = new_app()

def index():
    return "..."


First, in any view project, you need a file to contain your app. By default, view expects it to be in under a variable called app. Again, you can change this via the app_path setting. You're also going to want an (assuming you named your App instance app), but more on that later.

from view import new_app

app = new_app()*, start: bool = False, config_path: Path | str | None = None, config_directory: Path | str | None = None, app_dealloc: Callback | None = None, store: bool = True, config: Config | None = None, error_class: type[Error] = Error) -> App

Create a new view app.


Name Type Description Default
start bool

Should the app be started automatically? (In a new thread)

config_path Path | str | None

Path of the target configuration file

config_directory Path | str | None

Directory path to search for a configuration

app_dealloc Callback | None

Callback to run when the App instance is freed from memory

store bool

Whether to store the app, to allow use from get_app()

config Config | None

Raw Config object to use instead of loading the config.

error_class type[Error]

Class to be recognized as the HTTP error object.


Generally, you're going to want one of the configuration files talked about earlier, but if you're against configuration files that's OK, 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).

# view.toml
dev = true

loader_path = "./my_custom_loader_path"

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.

# pyproject.toml
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

name = "your_view_app"
requires-python = ">=3.8"
authors = [
  { name = "Your Name", email = "" },
dependencies = [""]