Skip to content

Commit

Permalink
Update docs/website/docs/general-usage/resource.md
Browse files Browse the repository at this point in the history
  • Loading branch information
burnash authored Mar 11, 2024
1 parent 7e3dc9d commit b1c916d
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions docs/website/docs/general-usage/resource.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b1c916d

Please sign in to comment.