Skip to content

Uvicorn Helpers

lacme.uvicorn

Uvicorn integration helpers for lacme certificate management.

Provides functions to extract SSL configuration from a :class:~lacme.store.FileStore for use with uvicorn.run(). No extra dependencies required.

ssl_context_from_store

ssl_context_from_store(store: FileStore, domain: str) -> ssl.SSLContext

Build an :class:ssl.SSLContext from a stored certificate.

Useful for custom server configurations or non-uvicorn ASGI servers.

Raises:

Type Description
FileNotFoundError

If no certificate is stored for domain.

ValueError

If the stored bundle has no file paths.

ssl_kwargs_from_store

ssl_kwargs_from_store(store: FileStore, domain: str) -> dict[str, Any]

Return kwargs for uvicorn.run() with SSL cert/key from store.

Usage::

import uvicorn
from lacme.store import FileStore
from lacme.uvicorn import ssl_kwargs_from_store

store = FileStore("~/.lacme")
uvicorn.run("app:app", **ssl_kwargs_from_store(store, "example.com"))

Returns:

Type Description
dict[str, Any]

Dict with ssl_keyfile and ssl_certfile keys.

Raises:

Type Description
FileNotFoundError

If no certificate is stored for domain.

ValueError

If the stored bundle has no file paths.