Using pyinstrument to profile FastHTML apps
Briefly

FastHTML, built on Starlette, offers a ProfileMiddleware that profiles application performance using pyinstrument. This middleware can be invoked via a GET request parameter, `profile=1`, which triggers profiling and presents an HTML output. However, it is crucial to note that this middleware is strictly for development environments; using it in production is dangerous due to potential exposure of sensitive infrastructure details. Installation of the `pyinstrument` library is required prior to using the middleware, as it facilitates the performance tracking process.
Including a profiler like pyinstrument in a production environment is dangerous, as it exposes infrastructure and poses significant risks to user data.
The ProfileMiddleware class in FastHTML allows you to profile your application by using a GET parameter to trigger performance analysis with pyinstrument.
To use the profiling middleware, simply add `?profile=1` to your request, and you'll receive an HTML report of your application's performance.
FastHTML is built on Starlette, utilizing its middleware capabilities to enhance applications with profiling features.
Read at daniel.feldroy.com
[
|
]