Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: change the ExperimentalFeatures.DTO_CODEGEN description #3802

Merged
merged 2 commits into from
Oct 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 57 additions & 30 deletions docs/usage/dto/0-basic-use.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,14 @@ DTOs can similarly be defined on :class:`Routers <litestar.router.Router>` and


Improving performance with the codegen backend
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. note::

This feature was introduced in ``2.2.0`` and hidden behind the ``DTO_CODEGEN``
feature flag. As of ``2.8.0`` it is considered stable and enabled by default. It can
still be disabled selectively by using the
``DTOConfig(experimental_codegen_backend=True)`` override.

This feature was introduced in ``2.2.0`` and was hidden behind the ``DTO_CODEGEN``
feature flag. As of ``2.8.0`` it is considered stable and is enabled by default.
It can still be disabled selectively by using the
``DTOConfig(experimental_codegen_backend=False)`` override.

The DTO backend is the part that does the heavy lifting for all the DTO features. It
is responsible for the transforming, validation and parsing. Because of this,
Expand All @@ -93,21 +92,11 @@ introduced by the DTOs, the DTO codegen backend was introduced; A DTO backend th
increases efficiency by generating optimized Python code at runtime to perform all the
necessary operations.

Enabling the backend
--------------------

You can enable this backend globally for all DTOs by passing the appropriate feature
flag to your Litestar application:

.. code-block:: python

from litestar import Litestar
from litestar.config.app import ExperimentalFeatures

app = Litestar(experimental_features=[ExperimentalFeatures.DTO_CODEGEN])

Disabling the backend
---------------------

or selectively for individual DTOs:
You can use ``experimental_codegen_backend=False``
to disable the codegen backend selectively:

.. code-block:: python

Expand All @@ -121,23 +110,61 @@ or selectively for individual DTOs:


class FooDTO(DataclassDTO[Foo]):
config = DTOConfig(experimental_codegen_backend=True)
config = DTOConfig(experimental_codegen_backend=False)

The same flag can be used to disable the backend selectively:
Enabling the backend
--------------------

.. code-block:: python
.. note:: This is a historical document meant for Litestar versions prior to 2.8.0
This backend was enabled by default since 2.8.0

from dataclasses import dataclass
from litestar.dto import DTOConfig, DataclassDTO
.. warning:: ``ExperimentalFeatures.DTO_CODEGEN`` is deprecated and will be removed in 3.0.0

.. dropdown:: Enabling DTO codegen backend
:icon: git-pull-request-closed

@dataclass
class Foo:
name: str
You can enable this backend globally for all DTOs by passing the appropriate feature
flag to your Litestar application:

.. code-block:: python

class FooDTO(DataclassDTO[Foo]):
config = DTOConfig(experimental_codegen_backend=False)
from litestar import Litestar
from litestar.config.app import ExperimentalFeatures

app = Litestar(experimental_features=[ExperimentalFeatures.DTO_CODEGEN])


or selectively for individual DTOs:

.. code-block:: python

from dataclasses import dataclass
from litestar.dto import DTOConfig, DataclassDTO


@dataclass
class Foo:
name: str


class FooDTO(DataclassDTO[Foo]):
config = DTOConfig(experimental_codegen_backend=True)

The same flag can be used to disable the backend selectively:

.. code-block:: python

from dataclasses import dataclass
from litestar.dto import DTOConfig, DataclassDTO


@dataclass
class Foo:
name: str


class FooDTO(DataclassDTO[Foo]):
config = DTOConfig(experimental_codegen_backend=False)


Performance improvements
Expand Down
Loading