You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+25-6Lines changed: 25 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -36,8 +36,7 @@ config = TFEConfig(
36
36
37
37
client = TFEClient(config)
38
38
39
-
orgs = client.organizations.list()
40
-
for org in orgs.items:
39
+
for org in client.organizations.list():
41
40
print(org.name)
42
41
```
43
42
@@ -57,8 +56,7 @@ from pytfe import TFEClient, TFEConfig
57
56
58
57
# Equivalent to providing no values; falls back to env vars if set.
59
58
client = TFEClient(TFEConfig())
60
-
orgs = client.organizations.list()
61
-
for org in orgs.items:
59
+
for org in client.organizations.list():
62
60
print(org.name)
63
61
```
64
62
@@ -69,11 +67,32 @@ from pytfe import TFEClient, TFEConfig
69
67
config = TFEConfig(address="", token="")
70
68
client = TFEClient(config)
71
69
72
-
orgs = client.organizations.list()
73
-
for org in orgs.items:
70
+
for org in client.organizations.list():
74
71
print(org.name)
75
72
```
76
73
74
+
## Listing resources
75
+
76
+
Anything named `list` or `list_*` on a resource service returns an **iterator**, not a Python `list`. Pagination is handled for you under the hood — the iterator keeps fetching pages from the API until there are no more. This mirrors the underlying HCP Terraform API, where every list endpoint is paginated (`page[number]` / `page[size]`), and keeps memory flat even when an organization has thousands of workspaces or runs.
77
+
78
+
You'll use it one of two ways:
79
+
80
+
```python
81
+
# Stream — handy when you might break early or when results are large
82
+
for ws in client.workspaces.list("my-org"):
83
+
if ws.name.startswith("prod-"):
84
+
print(ws.id, ws.name)
85
+
86
+
# Materialize — when you actually want a list to index, len(), or pass around
- The iterator is **single-use**. Once you've walked it, iterating again gives you nothing. Capture it with `list(...)` first if you need to reuse the result.
94
+
- Filters and page size live on the `*ListOptions` model for each resource — e.g. `WorkspaceListOptions(search="prod", page_size=50)`. Pagination still happens transparently; `page_size` only controls how big each underlying API page is.
0 commit comments