Configuration

Introduction

Before you can make any projects with view.py, you should learn about how it handles configuration. Configuration is handled by the configzen library under the hood, so most questions about configuration will be answered there.

The Config File

When creating your app, view will search for one of the following configuration files:

Note that while all of these are different formats, they can all evaluate to the same thing internally. If you have any questions on these semantics, once again see configzen.

Programatically

Many Python users aren't fond of the configuration file strategy, and that's okay. View supports editing the config at runtime just fine through the config property. The config property stores a Config object, which holds more subcategories.

app = new_app()
app.config.foo.bar = "..."

view.config.Config

Bases: ConfigModel

app: AppConfig = ConfigField(default_factory=AppConfig) class-attribute instance-attribute

dev: bool = True class-attribute instance-attribute

log: LogConfig = ConfigField(default_factory=LogConfig) class-attribute instance-attribute

server: ServerConfig = ConfigField(default_factory=ServerConfig) class-attribute instance-attribute

templates: TemplatesConfig = ConfigField(default_factory=TemplatesConfig) class-attribute instance-attribute

Configurations are loaded at runtime by the load_config function. If you would like to use View's configuration file without creating an App, you may use it like so:

from view import load_config

config = load_config()

view.config.load_config(path: Path | None = None, *, directory: Path | None = None) -> 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

Settings

View has several different configuration settings. For documentation purposes, values will be talked about in terms of Python (i.e. null values will be regarded as None).

At the top level, there's one real setting: dev.

dev is True by default, and is what tells view.py whether you're running in a production server setting or just running on your local machine.

Environment Variables

If you would like to set a configuration setting via an environment variable, you must account for the setting's environment prefix.

All environment prefixes look like view_<subcategory>_. For example, the loader setting is under the app section, so to set loader you would use the following command:

$ export view_app_loader=filesystem

App Settings

Environment Prefix: view_app_

Example with TOML:

[app]
loader = "filesystem"
loader_path = "./app"

Server Settings

Environment Prefix: view_server_

Example with TOML:

[server]
host = "localhost"
port = 8080

Log Settings

Environment Prefix: view_log_

User Logging Settings

Environment Prefix: view_user_log_

Example with TOML:

[log]
level = "warning"
fancy = false

[log.user]
log_file = "app.log"

Template Settings

Environment Prefix: view_templates_

Example with TOML:

[templates]
directory = "./pages"
engine = "jinja"