Skip to content

StaticFilesConfig class

Reference for the StaticFilesConfig class object and how to use it.

Read more about how to use the StaticFilesConfig in your application and leverage the system.

How to import

from ravyn import StaticFilesConfig

ravyn.core.config.static_files.StaticFilesConfig

Bases: BaseModel

An instance of StaticFilesConfig.

This configuration is used to enable and serve static files via Ravyn application.

Example

from ravyn import Ravyn
from ravyn.config import StaticFilesConfig

static_files_config = StaticFilesConfig(
    path="/static", directory=Path("static")
)

app = Ravyn(static_files_config=static_files_config)
# or multiple in descending priority
app = Ravyn(static_files_config=[static_files_config1, static_files_config2, ...])

path instance-attribute

path

The path for the statics.

directory class-attribute instance-attribute

directory = None

The directory for the statics in the format of a path like.

Example: /static.

html class-attribute instance-attribute

html = False

Run in HTML mode. Automatically loads index.html for directories if such file exist.

packages class-attribute instance-attribute

packages = None

A list of strings or list of tuples of strings of python packages.

check_dir class-attribute instance-attribute

check_dir = True

Ensure that the directory exists upon instantiation.

name class-attribute instance-attribute

name = None

The name of the static files to be looked up at.

fall_through class-attribute instance-attribute

fall_through = False

Activate fall-through routing.

follow_symlink = False

Follow symlinks.

validate_path

validate_path(value)
Source code in ravyn/core/config/static_files.py
105
106
107
108
109
@field_validator("path")
def validate_path(cls, value: str) -> str:
    if "{" in value:
        raise ValueError("path parameters are not supported for static files")
    return clean_path(value)

to_app

to_app()

It can be three scenarios

Source code in ravyn/core/config/static_files.py
111
112
113
114
115
116
def to_app(self) -> ASGIApp:
    """
    It can be three scenarios
    """

    return StaticFiles(**self.model_dump(exclude_none=True, exclude=["path", "name"]))  # type: ignore
    - "!^validate_path"
    - "!^to_app"
    - "!^_build_kwargs"