Skip to content

anystore.settings

Settings

Bases: BaseSettings

anystore settings management using pydantic-settings

Note

All settings can be set via environment variables in uppercase, prepending ANYSTORE_ (except for those with a given prefix)

Backend config: Use __ as a separator for dictionary content, e.g.: ANYSTORE_BACKEND_CONFIG__REDIS_PREFIX="foo"

Source code in anystore/settings.py
class Settings(BaseSettings):
    """
    `anystore` settings management using
    [pydantic-settings](https://docs.pydantic.dev/latest/concepts/pydantic_settings/)

    Note:
        All settings can be set via environment variables in uppercase,
        prepending `ANYSTORE_` (except for those with a given prefix)

        Backend config: Use `__` as a separator for dictionary content, e.g.:
        `ANYSTORE_BACKEND_CONFIG__REDIS_PREFIX="foo"`
    """

    model_config = SettingsConfigDict(
        env_prefix="anystore_",
        env_nested_delimiter="__",
        nested_model_default_partial_update=True,
    )

    uri: str = ".anystore"
    """Default store base uri"""

    yaml_uri: str | None = None
    """Load a (remote) store configuration (yaml) from this uri"""

    json_uri: str | None = None
    """Load a (remote) store configuration (json) from this uri"""

    serialization_mode: Mode = "auto"
    """Default serialization mode, one of ("auto", "pickle", "json", "raw")"""

    raise_on_nonexist: bool = True
    """Silence errors for non-existing keys"""

    default_ttl: int = 0
    """Key ttl for backends that support it (e.g. redis, sql)"""

    backend_config: dict[str, Any] = {}
    """Arbitrary backend config to pass through"""

    debug: bool = Field(alias="debug", default=False)
    """Enable debug mode"""

    redis_debug: bool = Field(alias="redis_debug", default=False)
    """Use fakeredis when using redis backend"""

    log_json: bool = Field(alias="log_json", default=False)
    """Enable json log format"""

    log_level: str = Field(alias="log_level", default="info")
    """Log level (debug, info, warning, error)"""

    worker_threads: int = Field(alias="worker_threads", default=cpu_count())
    """Default number of threads to use for workers"""

    worker_heartbeat: int = Field(alias="worker_heartbeat", default=15)
    """Default heartbeat for worker logging"""

    use_cache: bool = Field(alias="cache", default=True)
    """Globally enable or disable caching (used in @anycache decorator)"""

backend_config = {} class-attribute instance-attribute

Arbitrary backend config to pass through

debug = Field(alias='debug', default=False) class-attribute instance-attribute

Enable debug mode

default_ttl = 0 class-attribute instance-attribute

Key ttl for backends that support it (e.g. redis, sql)

json_uri = None class-attribute instance-attribute

Load a (remote) store configuration (json) from this uri

log_json = Field(alias='log_json', default=False) class-attribute instance-attribute

Enable json log format

log_level = Field(alias='log_level', default='info') class-attribute instance-attribute

Log level (debug, info, warning, error)

raise_on_nonexist = True class-attribute instance-attribute

Silence errors for non-existing keys

redis_debug = Field(alias='redis_debug', default=False) class-attribute instance-attribute

Use fakeredis when using redis backend

serialization_mode = 'auto' class-attribute instance-attribute

Default serialization mode, one of ("auto", "pickle", "json", "raw")

uri = '.anystore' class-attribute instance-attribute

Default store base uri

use_cache = Field(alias='cache', default=True) class-attribute instance-attribute

Globally enable or disable caching (used in @anycache decorator)

worker_heartbeat = Field(alias='worker_heartbeat', default=15) class-attribute instance-attribute

Default heartbeat for worker logging

worker_threads = Field(alias='worker_threads', default=cpu_count()) class-attribute instance-attribute

Default number of threads to use for workers

yaml_uri = None class-attribute instance-attribute

Load a (remote) store configuration (yaml) from this uri