Skip to content

Commit

Permalink
clean up examples
Browse files Browse the repository at this point in the history
  • Loading branch information
sh-rp committed Sep 28, 2023
1 parent 84a83c1 commit eb7b780
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 17 deletions.
6 changes: 6 additions & 0 deletions docs/examples/incremental_loading/.dlt/secrets.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[zendesk.sources.credentials]
password = ""
subdomain = ""
token = ""
email = ""
oauth_token = ""
6 changes: 3 additions & 3 deletions docs/examples/incremental_loading/run.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Iterator, Optional, Dict, Any, Sequence
from typing import Iterator, Optional, Dict, Any, Tuple

import dlt
from dlt.common import pendulum
Expand All @@ -11,7 +11,7 @@
@dlt.source(max_table_nesting=2)
def zendesk_support(
credentials=dlt.secrets.value,
start_date: Optional[TAnyDateTime] = pendulum.datetime(year=2000, month=1, day=1),
start_date: Optional[TAnyDateTime] = pendulum.datetime(year=2000, month=1, day=1), # noqa: B008
end_date: Optional[TAnyDateTime] = None,
) -> DltResource:
"""
Expand Down Expand Up @@ -71,7 +71,7 @@ def ticket_events(
def get_pages(
url: str,
endpoint: str,
auth: Sequence[str],
auth: Tuple[str, str],
data_point_name: str,
params: Optional[Dict[str, Any]] = None,
) -> Iterator[TDataItems]:
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/transformers/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async def pokemon(pokemon: TDataItem):
Yields:
dict: The pokemon full data.
"""
# just return the results, if you yield,
# just return the results, if you yield,
# generator will be evaluated in main thread
return requests.get(pokemon["url"]).json()

Expand All @@ -38,7 +38,7 @@ async def species(pokemon: TDataItem):
Yields:
dict: The species full data.
"""
# just return the results, if you yield,
# just return the results, if you yield,
# generator will be evaluated in main thread
species_data = requests.get(pokemon["species"]["url"]).json()
# optionally add pokemon_id to result json, to later be able
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
def incremental_snippet() -> None:

# @@@DLT_SNIPPET_START example
from typing import Iterator, Optional, Dict, Any, Sequence
from typing import Iterator, Optional, Dict, Any, Tuple

import dlt
from dlt.common import pendulum
Expand All @@ -16,7 +16,7 @@ def incremental_snippet() -> None:
@dlt.source(max_table_nesting=2)
def zendesk_support(
credentials=dlt.secrets.value,
start_date: Optional[TAnyDateTime] = pendulum.datetime(year=2000, month=1, day=1),
start_date: Optional[TAnyDateTime] = pendulum.datetime(year=2000, month=1, day=1), # noqa: B008
end_date: Optional[TAnyDateTime] = None,
) -> DltResource:
"""
Expand Down Expand Up @@ -76,7 +76,7 @@ def ticket_events(
def get_pages(
url: str,
endpoint: str,
auth: Sequence[str],
auth: Tuple[str, str],
data_point_name: str,
params: Optional[Dict[str, Any]] = None,
) -> Iterator[TDataItems]:
Expand Down Expand Up @@ -124,3 +124,7 @@ def get_pages(
print(load_info)
# @@@DLT_SNIPPET_END example

# check that stuff was loaded
row_counts = pipeline.last_trace.last_normalize_info.row_counts
assert row_counts["ticket_events"] == 24

6 changes: 3 additions & 3 deletions docs/website/docs/examples/incremental_loading/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ In this example, you'll find a Python script that interacts with the Zendesk Sup

<!--@@@DLT_SNIPPET_START ./code/run-snippets.py::example-->
```py
from typing import Iterator, Optional, Dict, Any, Sequence
from typing import Iterator, Optional, Dict, Any, Tuple

import dlt
from dlt.common import pendulum
Expand All @@ -43,7 +43,7 @@ from dlt.sources.helpers.requests import client
@dlt.source(max_table_nesting=2)
def zendesk_support(
credentials=dlt.secrets.value,
start_date: Optional[TAnyDateTime] = pendulum.datetime(year=2000, month=1, day=1),
start_date: Optional[TAnyDateTime] = pendulum.datetime(year=2000, month=1, day=1), # noqa: B008
end_date: Optional[TAnyDateTime] = None,
) -> DltResource:
"""
Expand Down Expand Up @@ -103,7 +103,7 @@ def zendesk_support(
def get_pages(
url: str,
endpoint: str,
auth: Sequence[str],
auth: Tuple[str, str],
data_point_name: str,
params: Optional[Dict[str, Any]] = None,
) -> Iterator[TDataItems]:
Expand Down
8 changes: 4 additions & 4 deletions docs/website/docs/examples/transformers/code/run-snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ async def pokemon(pokemon: TDataItem):
Yields:
dict: The pokemon full data.
"""
# just return the results, if you yield,
# just return the results, if you yield,
# generator will be evaluated in main thread
return requests.get(pokemon["url"]).json()


# asynchronously retrieve details for the species of each pokemon
@dlt.transformer(data_from=pokemon)
Expand All @@ -42,7 +42,7 @@ async def species(pokemon: TDataItem):
Yields:
dict: The species full data.
"""
# just return the results, if you yield,
# just return the results, if you yield,
# generator will be evaluated in main thread
species_data = requests.get(pokemon["species"]["url"]).json()
# optionally add pokemon_id to result json, to later be able
Expand All @@ -55,7 +55,7 @@ async def species(pokemon: TDataItem):
pipeline = dlt.pipeline(
pipeline_name="pokemon", destination="duckdb", dataset_name="pokemon_data"
)

# the pokemon_list resource does not need to be loaded
load_info = pipeline.run([pokemon(), species()])
print(load_info)
Expand Down
4 changes: 2 additions & 2 deletions docs/website/docs/examples/transformers/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ async def pokemon(pokemon: TDataItem):
Yields:
dict: The pokemon full data.
"""
# just return the results, if you yield,
# just return the results, if you yield,
# generator will be evaluated in main thread
return requests.get(pokemon["url"]).json()

Expand All @@ -63,7 +63,7 @@ async def species(pokemon: TDataItem):
Yields:
dict: The species full data.
"""
# just return the results, if you yield,
# just return the results, if you yield,
# generator will be evaluated in main thread
species_data = requests.get(pokemon["species"]["url"]).json()
# optionally add pokemon_id to result json, to later be able
Expand Down

0 comments on commit eb7b780

Please sign in to comment.