starlette-async-jinja


License
BSD-3-Clause
Install
pip install starlette-async-jinja==1.7.8

Documentation

starlette-async-jinja

Code style: crackerjack

Jinja2 is_async template support for Starlette +

About

  • Provides AsyncJinja2Templates class which enables use of the is_async Jinja environment flag with Startlette and Starlette based applications like FastAPI
  • Integrated Jinja Partials and Jinja Fragments
  • Supports asynchronous template loaders (examples here)

Issues

  • Only asynchronous template loaders (not yet tested but should work) are currently supported

  • The Jinja bytecodecache requires an asynchronous Redis backend

Usage

Import AsyncJinja2Templates:

from starlette_async_jinja import AsyncJinja2Templates

Replace Jinja2Templates with AsyncJinja2Templates:

templates = AsyncJinja2Templates(directory='templates')

Render the async template in the response:

async def homepage(request: Request):
    return await templates.TemplateResponse(request, 'index.html')

or:

async def homepage(request: Request):
    return await templates.render_template(request, 'index.html')

Acknowledgements

License

BSD-3-Clause