Migrating from v2 to v3
fasthx was first developed with Jinja templating and HTML rendering in mind. The feature set of the project grew significantly since then, for example with error rendering support and htmy integration, among other, smaller improvements.
More features and integrations are planned, and the main goal of this upgrade is to prepare the project structure for them.
Summary of major changes:
- All Jinja-related code now lives in
fasthx.jinjaand can only be imported from that package. *HTMLRenderertypes have been renamed to*RenderFunctionto prepare for rendering non-HTML content.- The
RenderFunctiontype has changed:Responseis no longer allowed as the return value. - Updated the required
htmyversion to>=0.8.1.
Upgrade steps (general)
These are all typing-related changes and most likely not relevant to your project unless you have created custom render functions or integrations.
- Replace
from fasthx import HTMLRendererwithfrom fasthx import RenderFunction. - Replace
from fasthx.typing import HTMLRendererwithfrom fasthx.typing import RenderFunction. - Replace
from fasthx.typing import SyncHTMLRendererwithfrom fasthx.typing import SyncRenderFunction. - Replace
from fasthx.typing import AsyncHTMLRendererwithfrom fasthx.typing import AsyncRenderFunction.
Upgrade steps (Jinja)
These are mostly import changes — all the Jinja-related utilities can now only imported from fasthx.jinja — and the renaming of TemplateHeader to ComponentHeader.
- Replace
from fasthx import Jinjawithfrom fasthx.jinja import Jinja. - Replace
from fasthx import JinjaContextwithfrom fasthx.jinja import JinjaContext. - Replace
from fasthx import JinjaPathwithfrom fasthx.jinja import JinjaPath. - Replace
from fasthx import TemplateHeaderwithfrom fasthx.jinja import ComponentHeader. - Replace
from fasthx.jinja import TemplateHeaderwithfrom fasthx.jinja import ComponentHeader. - Replace
from fasthx import JinjaContextFactorywithfrom fasthx.jinja import JinjaContextFactory. - Replace
from fasthx.typing import JinjaContextFactorywithfrom fasthx.jinja import JinjaContextFactory. - Instead of the
templatesargument ofTemplateHeader(), you must use thecomponentsargument ofComponentHeader, if you passedtemplatesas a keyword argument. Jinja._make_response()has been removed to simplify the codebase. If you have overridden it, you must now overrideJinja._make_render_function()instead.
Upgrade steps (htmy)
- Make sure you're using
htmyversion>=0.8.1. - The
HTMYinstance no longer has anhtmyproperty; it has been replaced by therendererproperty.
Upgrade steps (custom rendering)
RenderFunctionmust return astr,Responseis no longer allowed.