Skip to content

Others

configuration.py

Configuration declaration & parsing.

DefaultConfig dataclass

Default configuration, with sensible defaults whenever possible.

Source code in oblique/configuration.py
19
20
21
22
23
24
25
26
27
28
29
30
@dataclass
class DefaultConfig:
    """Default configuration, with sensible defaults whenever possible."""

    # Server
    host: str = "0.0.0.0"
    port: int = 9810

    # Database
    db: str = "${oc.env:OBLIQUE_DB,memory}"
    db_url: str = "${db_url:${db}}"
    db_path: str = "${oc.env:OBLIQUE_DB_PATH,db.sql}"

dependencies.py

Dependencies used in both the web-app and the API.

get_db()

FastAPI dependency to create a DB Session.

Yields:

Name Type Description
SessionLocal SessionLocal

DB Session.

Source code in oblique/dependencies.py
 5
 6
 7
 8
 9
10
11
12
13
14
15
def get_db() -> SessionLocal:
    """FastAPI dependency to create a DB Session.

    Yields:
        SessionLocal: DB Session.
    """
    db = SessionLocal()
    try:
        yield db
    finally:
        db.close()

server.py

File containing the main function, serving the app.

get_main_app()

Create the main FastAPI app, which is made of the web-app and the API.

Source code in oblique/server.py
13
14
15
16
17
18
19
20
21
22
23
def get_main_app():
    """Create the main FastAPI app, which is made of the web-app and the API."""
    main_app = FastAPI(title="Oblique", version=__version__, redoc_url=None)

    main_app.add_exception_handler(*api_handler)
    main_app.add_exception_handler(*app_handler)

    main_app.include_router(app_router, tags=["HTML"])
    main_app.include_router(api_router, prefix="/api", tags=["API"])

    return main_app

run()

The function called to run the server.

It will simply run the FastAPI app. Also, if the selected DB is in-memory, it will ensure the tables are created.

Source code in oblique/server.py
26
27
28
29
30
31
32
33
34
35
36
def run():
    """The function called to run the server.

    It will simply run the FastAPI app. Also, if the selected DB is in-memory,
    it will ensure the tables are created.
    """
    if config.db == "memory":
        crud.create_tables()

    main_app = get_main_app()
    uvicorn.run(main_app, host=config.host, port=config.port)

Constants

These constants are located in oblique/__init__.py.