Settings

Settings

class progress_updater.backends.Settings(_env_file: Optional[Union[str, PathLike, List[Union[str, PathLike]], Tuple[Union[str, PathLike], ...]]] = '<object object>', _env_file_encoding: Optional[str] = None, _env_nested_delimiter: Optional[str] = None, _secrets_dir: Optional[Union[str, PathLike]] = None, *, pu: Union[RedisSettings, MongoSettings, SQLSettings])

Defines a wrapper around the different settings.

You can pass settings directly or define them as ENV vars on your system.

1. Passing settings as parameters when creating a Settings object:

>>> from progress_updater import ProgressUpdater
>>> from progress_updater.backends import MongoSettings
>>>
>>> mongo_settings = MongoSettings(
>>>     mongo_connection="mongodb://user:pass@mongo:27017",
>>>     mongo_db="db",
>>>     mongo_collection="logs",
>>> )
>>> settings = Settings(pu=mongo_settings)

2. Environment variables. Set you setting parameters in your environment. The PU__ prefix indicates that belongs to the ProgressUpdater settings. The ProgressUpdater will catch these settings if the option write_on_backend is set to True.

Examples:

SQL:

PU__SQL_DSN='postgresql+psycopg2://user:pass@postgres:5432/db'
PU__SQL_TABLE='logs'

Redis:

PU__REDIS_HOST='redis'
PU__REDIS_DB='1'
PU__REDIS_PASSWORD='pass'

Mongo:

PU__MONGO_CONNECTION='mongodb://user:pass@mongo:27017'
PU__MONGO_DB='db'
PU__MONGO_COLLECTION='logs'

And then when creating a ProgressUpdater object, the backend will be automatically configured:

>>> from progress_updater.backends import Settings
>>>
>>> updater = Settings()
backend()

Return a Backend (Redis, Mongo, SQL) with configuration already set up.