Skip to content

odmantic.fastapi

odmantic.fastapi.AIOEngineDependency

AIOEngine FastAPI Dependency.

Warning

Deprecated since v0.2.0, more details.

Internally caches the AIOEngine instance to avoid creating a new client on each request.

Sample usage:

app = FastAPI()
EngineD = AIOEngineDependency()

@app.get("/")
async def get(engine: AIOEngine = EngineD):
    await engine.find(...)
    await engine.save(...)

__init__(self, mongo_uri=None, database='test') special

Dependency initializer for AIOEngine.

Parameters:

Name Type Description Default
mongo_uri Optional[str]

mongo_uri that should be used for creating the motor client

None
database str

database to use

'test'
Source code in odmantic/fastapi.py
def __init__(self, mongo_uri: Optional[str] = None, database: str = "test") -> None:
    """Dependency initializer for AIOEngine.

    Args:
        mongo_uri: mongo_uri that should be used for creating the motor client
        database: database to use
    """
    super().__init__(dependency=self)
    self.mongo_uri = mongo_uri
    self.database = database
    self.engine: Optional[AIOEngine] = None
    warnings.warn(
        "the AIOEngineDependency object is deprecated, see "
        "https://art049.github.io/odmantic/usage_fastapi/#building-the-engine "
        "for more details.",
        DeprecationWarning,
    )