.. _spec: ======================= Framework specification ======================= Learn how to build a :ref:`web-poet framework `. Design principles ================= :ref:`Page objects ` should be flexible enough to be used with: * synchronous or asynchronous code, callback-based and ``async def / await`` based, * single-node and distributed systems, * different underlying HTTP implementations - or without HTTP support at all, etc. Minimum requirements ==================== A web-poet framework must support building a :ref:`page object ` given a page object class. It must be able to build :ref:`input objects ` for a page object based on type hints on the page object class, i.e. dependency injection, and additional input data required by those input objects, such as a target URL or a dictionary of :ref:`page parameters `. You can implement dependency injection with the andi_ library, which handles signature inspection, :data:`~typing.Optional` and :data:`~typing.Union` annotations, as well as indirect dependencies. For practical examples, see the source code of :mod:`web_poet.framework` and of :doc:`scrapy-poet `. .. _andi: https://github.com/scrapinghub/andi Additional features =================== To provide a better experience to your users, consider extending your web-poet framework further to: - Support as many input classes from the :mod:`web_poet.page_inputs` module as possible. - Support returning a :ref:`page object ` given a target URL and a desired :ref:`output item class `, determining the right :ref:`page object class ` to use based on :ref:`rules `. - Allow users to request an :ref:`output item ` directly, instead of requesting a page object just to call its ``to_item`` method. If you do, consider supporting both synchronous and asynchronous definitions of the ``to_item`` method, e.g. using :func:`~.ensure_awaitable`. - Support :ref:`additional requests `. - Support :ref:`retries `. - Let users set their own :ref:`rules `, e.g. to :ref:`solve conflicts `.