Configuration¶
Config file¶
Configuration file is located in apps/config.py. Also, additional parameters could be provided via environment variables with prefix PANTRA_.
There are two ways to declare parameters in config.py:
As global variable (old style):
MIN_TASK_THREADS = 1 MAX_TASK_THREADS = 2
As AppConfig subclass attributes (recommended):
from pantra.defaults import Config class AppConfig(Config): MIN_TASK_THREADS = 1 MAX_TASK_THREADS = 2
Environment variables¶
pantra also reads environment variables, prefixed with PANTRA_. There is value parsing convention to detect types:
1234 - anything starting with a digit -> is a number
True or False -> is a boolean value
None -> literally None
Any other value is a string
PANTRA_MIN_TASK_THREADS=1
PANTRA_MAX_TASK_THREADS=2
pantra run
Parameters list¶
- class pantra.defaults.Config[source]¶
Default configuration class
- BASE_PATH: Path = Path('.')¶
Base project path
- COMPONENTS_PATH: Path = Path('components')¶
Path to components directory
- CSS_PATH: Path = Path('css')¶
Path to common CSS files
- JS_PATH: Path = Path('pantra/js')¶
Path to pantra engine JS core
- APPS_PATH: Path = Path('apps')¶
Path to apps directory
- CACHE_PATH: Path = Path('cached')¶
Path to pre-cached components
- RUN_CACHED: bool = False¶
Load components from pre-cached directory
- DEFAULT_RENDERER: str | type[RendererBase] = '{pantra.components.render.renderer_html:RendererHTML}'¶
Canonic path to default renderer class
- ROUTER_CLASS: str | type[BaseRouter] = '{pantra.routes:DevRouter}'¶
Canonic path to HTTP router
- SETUP_LOGGER(level: int = 10)¶
Reference to setup logger function (arg is logging.LEVEL)
- Parameters:
level (int)
- WORKERS_MODULE: str = '{pantra.workers.memory}'¶
Canonical path to message queue module
- SESSION_STORAGE: str | type[SessionStorage] = '{pantra.session_storage:NullSessionStorage}'¶
User settings storage, see
SessionStorage
Config API¶
To access parameters in a code use two global variables:
safe_config - contains constant values only, which is possible to evaluate literally (without calls). It is safe to use on start time. to avoid modules import recursion:
from pantra.settings import safe_config if safe_config.PRODUCTION: print("Early stage initialization")
config- contains all evaluated (later) parameters:
from pantra.settings import config print(config.DEFAULT_APP)