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:

  1. As global variable (old style):

    MIN_TASK_THREADS = 1
    MAX_TASK_THREADS = 2
    
  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

WEB_PATH: str = ''

Own web application URL to refer web resources

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

STATIC_DIR: str = 'static'

Default subdirectory name to contain static media (font, images, etc.)

ALLOWED_DIRS: dict[str, Path] = {}

Dictionary alias -> full path to allow static links

DEFAULT_APP: str = 'Core'

Default app name

DEFAULT_LANGUAGE: str = 'en'

Default language code

PRODUCTIVE: bool = False

Flag app as “productive-ready”

RUN_CACHED: bool = False

Load components from pre-cached directory

MIN_TASK_THREADS: int = 2

Min. amount of threads to execute clicks/callbacks

MAX_TASK_THREADS: int = 100

Max. amount of threads. Check threads

CREATE_THREAD_LAG: int = 3

Time in seconds to wait for relaxed thread before create one

KILL_THREAD_LAG: int = 300

Kill redundant threads after specified amount of seconds

THREAD_TIMEOUT: int = 0

Kill occupied thread if it hangs for too long

SOCKET_TIMEOUT: int = 180

Amount of seconds to wait websocket connection restored

WS_HEARTBEAT_INTERVAL: float | None = None

Websocket ping interval to support connection

SESSION_TTL: int = 1800

Reset passive user session after specified amount of seconds

MAX_MESSAGE_SIZE: int = 4194304

Websocket max message size in bytes

LOCKS_TIMEOUT: int = 5

Amount of seconds to wait requested data from client side

SHOTS_PER_SECOND: int = 25

Max fps for flickering shots (resize, grab/move, etc)

BOOTSTRAP_FILENAME: Path = Path('components/bootstrap.html')

Path to bootstrap template

APP_TITLE: str = 'Pantra Web App'

Page title in the browser

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

WIPE_LOGGING: bool = False

Eliminate pantra core logs on byte-code level

LOG_LEVEL: Literal['error', 'warning', 'info', 'debug'] = 'info'

Set logger depth

ENABLE_WATCHDOG: bool = False

Watch for files updates in real-time to reload components

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

ZMQ_LISTEN: str = 'tcp://*:5555'

URI for ZeroMQ listener

ZMQ_HOST: str = 'tcp://localhost:5555'

URI for ZeroMQ connection

JS_SERIALIZER_LOGGING: bool = False

Dump to dev console serializer details

JS_WS_LOGGING: bool = False

Dump to dev console websocket connection details

JS_PROTO_LOGGING: bool = False

Dump to dev console websocket messages

JS_ADD_IDS: bool = False

Render explicit id attributes to each HTML node

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)