Skip to content

kamihi.web.web ⚓︎

Web interface main file.

License

MIT

Classes:

Name Description
KamihiWeb

KamihiWeb is a class that sets up a web server for the Kamihi application.

KamihiWeb ⚓︎

KamihiWeb(
    hooks: dict[
        Literal[
            "before_create",
            "after_create",
            "before_edit",
            "after_edit",
            "before_delete",
            "after_delete",
            "run_job",
        ],
        list[Callable],
    ] = None,
)

Bases: Thread

KamihiWeb is a class that sets up a web server for the Kamihi application.

This class is responsible for creating and running a web server with an admin interface. It also handles the database connection and configuration.

Attributes:

Name Type Description
app Starlette

The application instance.

admin Admin

The Starlette-Admin instance for the admin interface.

Initialize the KamihiWeb instance.

Methods:

Name Description
run

Run the app.

Source code in src/kamihi/web/web.py
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
def __init__(
    self,
    hooks: dict[
        Literal[
            "before_create", "after_create", "before_edit", "after_edit", "before_delete", "after_delete", "run_job"
        ],
        list[Callable],
    ] = None,
) -> None:
    """Initialize the KamihiWeb instance."""
    settings = get_settings()

    super().__init__()

    self.hooks = hooks
    self.host = settings.web.host
    self.port = settings.web.port

    self.daemon = True

    self.app = None
    self.admin = None

run ⚓︎

run() -> None

Run the app.

Source code in src/kamihi/web/web.py
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
def run(self) -> None:
    """Run the app."""
    self._create_app()

    uvicorn.run(
        self.app,
        host=self.host,
        port=self.port,
        log_config={
            "version": 1,
            "disable_existing_loggers": False,
            "formatters": {
                "default": {
                    "()": "uvicorn.logging.DefaultFormatter",
                    "fmt": "%(message)s",
                },
                "access": {
                    "()": "uvicorn.logging.AccessFormatter",
                    "fmt": '%(client_addr)s - "%(request_line)s" %(status_code)s',  # noqa: E501
                },
            },
            "handlers": {
                "default": {
                    "formatter": "default",
                    "class": "kamihi.web.web._InterceptHandler",
                },
                "access": {
                    "formatter": "access",
                    "class": "kamihi.web.web._InterceptHandler",
                },
            },
            "loggers": {
                "uvicorn": {"handlers": ["default"], "level": "DEBUG", "propagate": False},
                "uvicorn.error": {"level": "DEBUG"},
                "uvicorn.access": {"handlers": ["access"], "level": "DEBUG", "propagate": False},
            },
        },
    )