From b1c916d82ed948708d93f5827ada00a66297006d Mon Sep 17 00:00:00 2001 From: Anton Burnashev Date: Mon, 11 Mar 2024 21:57:45 +0300 Subject: [PATCH] Update docs/website/docs/general-usage/resource.md --- docs/website/docs/general-usage/resource.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/website/docs/general-usage/resource.md b/docs/website/docs/general-usage/resource.md index 24eb317796..2a5926f04c 100644 --- a/docs/website/docs/general-usage/resource.md +++ b/docs/website/docs/general-usage/resource.md @@ -223,6 +223,21 @@ the **pipe |** operator to bind resources dynamically pipeline.run(users(limit=100) | user_details) ``` +:::tip +Transformers are allowed not only to **yield** but also to **return** values and can decorate **async** functions and [**async generators**](../reference/performance.md#extract). Below we decorate an async function and request details on two pokemons. Http calls are made in parallel via httpx library. +```python +import dlt +import httpx + + +@dlt.transformer +async def pokemon(id): + async with httpx.AsyncClient() as client: + r = await client.get(f"https://pokeapi.co/api/v2/pokemon/{id}") + return r.json() + +# get bulbasaur and ivysaur (you need dlt 0.4.6 for pipe operator working with lists) +print(list([1,2] | pokemon())) ### Declare a standalone resource A standalone resource is defined on a function that is top level in a module (not an inner function) that accepts config and secrets values. Additionally, if the `standalone` flag is specified, the decorated function signature and docstring will be preserved. `dlt.resource` will just wrap the