Skip to content

Commit 40d7280

Browse files
authored
Improve python sdk docs (#2088)
1 parent 158de59 commit 40d7280

13 files changed

Lines changed: 56 additions & 1222 deletions

docs/docs.json

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -327,18 +327,7 @@
327327
"pages": [
328328
"python-sdk/api-reference/overview",
329329
"python-sdk/api-reference/test-decorators",
330-
"python-sdk/api-reference/table-assets",
331-
"python-sdk/api-reference/tests",
332-
"python-sdk/api-reference/test-executions"
333-
]
334-
},
335-
{
336-
"group": "Guides",
337-
"pages": [
338-
"python-sdk/guides/authentication",
339-
"python-sdk/guides/test-decorators",
340-
"python-sdk/guides/sending-data",
341-
"python-sdk/guides/best-practices"
330+
"python-sdk/api-reference/table-assets"
342331
]
343332
}
344333
]

docs/python-sdk/api-reference/overview.mdx

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ client = ElementaryCloudClient(project_id, api_key, url)
3939
Where:
4040
- `project_id` is your Python project identifier (chosen by you, used to deduplicate and identify reported assets)
4141
- `api_key` is your API token (generated from the steps above)
42-
- `url` is the full SDK ingest endpoint URL: `{base_url}/sdk-ingest/{env_id}/batch`
42+
- `url` is the full SDK ingest endpoint URL (the Elementary team will provide you with this URL): `{base_url}/sdk-ingest/{env_id}/batch`
4343
- Example: `https://app.elementary-data.com/sdk-ingest/a6b2425d-36e2-4e13-8458-9825688ca1f2/batch`
4444

4545
## Test Context
@@ -58,6 +58,17 @@ with elementary_test_context(asset=asset) as ctx:
5858
client.send_to_cloud(ctx)
5959
```
6060

61+
### `raise_on_error`
62+
63+
By default, `elementary_test_context` uses `raise_on_error=False`. This means that if a decorated test (or something inside the context) raises an exception, the SDK **captures it and records an `ERROR` execution** so you can still send results to Elementary Cloud without crashing your pipeline.
64+
65+
If you prefer **fail-fast** behavior (for example in CI), pass `raise_on_error=True` to re-raise exceptions after they are recorded:
66+
67+
```python
68+
with elementary_test_context(asset=asset, raise_on_error=True) as ctx:
69+
run_my_tests(df)
70+
```
71+
6172
## Test Decorators
6273

6374
The SDK provides decorators to define tests:
@@ -75,15 +86,17 @@ You can also use context managers for inline tests:
7586
with elementary_test_context(asset=asset) as ctx:
7687
# Using context managers
7788
with ctx.boolean_test(name="my_test", description="Inline test") as my_bool_test:
78-
my_bool_test.assert_value(False)
89+
my_bool_test.assert_value(my_test_function())
7990

8091
with ctx.expected_values_test(
8192
name="country_count",
8293
expected=[2, 3],
8394
allow_none=True,
8495
metadata={"my_metadata_field": "my_metadata_value"},
8596
) as my_expected_values_test:
97+
# This will fail
8698
my_expected_values_test.assert_value(5)
99+
# This will pass
87100
my_expected_values_test.assert_value(3)
88101

89102
with ctx.expected_range_test(
@@ -103,17 +116,14 @@ with elementary_test_context(asset=asset) as ctx:
103116

104117
## Supported Objects
105118

106-
The SDK supports three types of objects:
119+
The SDK supports reporting table assets and test results.
107120

108-
<CardGroup cols={3}>
121+
<CardGroup cols={2}>
109122
<Card title="Table Assets" icon="table" href="/python-sdk/api-reference/table-assets" >
110123
Register tables and views in your data warehouse
111124
</Card>
112-
<Card title="Tests" icon="flask" href="/python-sdk/api-reference/tests" >
113-
Define data quality tests
114-
</Card>
115-
<Card title="Test Executions" icon="play" href="/python-sdk/api-reference/test-executions" >
116-
Report test execution results
125+
<Card title="Test Decorators" icon="flask" href="/python-sdk/api-reference/test-decorators" >
126+
Define data quality tests using decorators
117127
</Card>
118128
</CardGroup>
119129

@@ -143,7 +153,6 @@ except Exception as e:
143153
- **Run multiple tests in one context** - All tests in a single `elementary_test_context` are automatically batched
144154
- **Use descriptive test names** - Clear names help identify tests in the Elementary UI
145155
- **Include asset metadata** - Add descriptions, owners, tags, and dependencies to assets
146-
- **Handle errors gracefully** - Wrap `send_to_cloud` calls in try-except blocks
147156

148157
<Tip>
149158
All tests run within a single `elementary_test_context` are automatically batched and sent together.
@@ -153,6 +162,5 @@ All tests run within a single `elementary_test_context` are automatically batche
153162

154163
- [Test Decorators](/python-sdk/api-reference/test-decorators) - Complete reference for all test decorators
155164
- [Table Assets](/python-sdk/api-reference/table-assets) - Learn about table asset structure
156-
- [Tests](/python-sdk/api-reference/tests) - Understand test definitions
157-
- [Test Executions](/python-sdk/api-reference/test-executions) - See how to report test results
165+
- [Quickstart](/python-sdk/quickstart) - Send your first test results to Elementary Cloud
158166

docs/python-sdk/api-reference/table-assets.mdx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ asset = TableAsset(
1717
description="string", # Optional: Table description
1818
owners=["string"], # Optional: List of owners (emails or usernames)
1919
tags=["string"], # Optional: List of tags
20-
depends_on=["string"] # Optional: List of upstream asset IDs
20+
depends_on=["string"] # Optional: List of upstream fully qualified table names
2121
)
2222
```
2323

@@ -37,7 +37,7 @@ asset = TableAsset(
3737
| `description` | string | Human-readable description of the table |
3838
| `owners` | list[string] | List of owners (email addresses or usernames) |
3939
| `tags` | list[string] | List of tags for categorization |
40-
| `depends_on` | list[string] | List of upstream asset IDs (e.g., `["prod.public.customers", "prod.public.orders"]`) for lineage tracking |
40+
| `depends_on` | list[string] | List of upstream fully qualified table names (e.g., `["prod.public.customers", "prod.public.orders"]`) for lineage tracking |
4141

4242
## Example
4343

@@ -75,7 +75,6 @@ Table assets are updated on each ingest, so include all current metadata in ever
7575

7676
## Related Documentation
7777

78-
- [Tests](/python-sdk/api-reference/tests) - Define tests for your table assets
79-
- [Test Executions](/python-sdk/api-reference/test-executions) - Report test results
80-
- [Sending Data Guide](/python-sdk/guides/sending-data) - Learn how to send table assets
78+
- [Test Decorators](/python-sdk/api-reference/test-decorators) - Define tests for your table assets
79+
- [API Reference](/python-sdk/api-reference/overview) - Overview of the SDK API
8180

docs/python-sdk/api-reference/test-decorators.mdx

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ def test_function(df: pd.DataFrame) -> bool:
4949
| `tags` | list[str] | No | `None` | List of tags |
5050
| `owners` | list[str] | No | `None` | List of owners |
5151
| `metadata` | dict | No | `None` | Additional metadata |
52-
| `quality_dimension` | QualityDimension | No | `None` | Quality dimension (defaults to VALIDITY if column_name is set) |
53-
| `skip` | bool | No | `False` | Whether to skip this test |
52+
| `quality_dimension` | QualityDimension | No | `None` | Quality dimension (defaults to VALIDITY) |
53+
| `skip` | bool | No | `False` | Whether to skip this test. Useful if you want the test to appear in Elementary Cloud, but you don't want to execute it in this run. |
5454

5555
### Example
5656

@@ -68,7 +68,7 @@ def test_unique_ids(df: pd.DataFrame) -> bool:
6868

6969
## @expected_range
7070

71-
Tests that return a numeric value that should fall within a range.
71+
Tests that return a numeric value that should fall within a range. They can also return a list of numeric values or a pandas Series.
7272

7373
### Signature
7474

@@ -86,9 +86,11 @@ Tests that return a numeric value that should fall within a range.
8686
quality_dimension: QualityDimension | None = None,
8787
skip: bool = False,
8888
)
89-
def test_function(df: pd.DataFrame) -> float:
89+
def test_function(df: pd.DataFrame) -> float | list[float] | pd.Series:
9090
# Your test logic
91-
return 25.5 # Numeric value
91+
return df["age"].mean() # Numeric value
92+
# return [1, 2, 3] # Numeric values
93+
# return df["age"] # pandas Series
9294
```
9395

9496
### Parameters
@@ -98,10 +100,7 @@ def test_function(df: pd.DataFrame) -> float:
98100
| `name` | str | Yes | - | Test name |
99101
| `min` | float | No | `None` | Minimum expected value (inclusive) |
100102
| `max` | float | No | `None` | Maximum expected value (inclusive) |
101-
| `severity` | str | No | `"ERROR"` | Test severity |
102-
| `description` | str | No | `None` | Test description |
103-
| `column_name` | str | No | `None` | Column being tested |
104-
| `tags`, `owners`, `metadata`, `quality_dimension`, `skip` | - | No | - | Same as `@boolean_test` |
103+
| `severity`, `description`, `column_name`, `tags`, `owners`, `metadata`, `quality_dimension`, `skip` | - | No | - | Same as `@boolean_test` |
105104

106105
### Example
107106

@@ -120,7 +119,7 @@ def test_average_age(df: pd.DataFrame) -> float:
120119

121120
## @expected_values
122121

123-
Tests that return a value that should match one of a list of expected values.
122+
Tests that return a value (or values) that should match one of a list of expected values.
124123

125124
### Signature
126125

@@ -150,10 +149,7 @@ def test_function(df: pd.DataFrame) -> Any:
150149
| `name` | str | Yes | - | Test name |
151150
| `expected` | Any \| list[Any] | Yes | - | Expected value(s) - can be single value or list |
152151
| `allow_none` | bool | No | `False` | Whether to allow None values |
153-
| `severity` | str | No | `"ERROR"` | Test severity |
154-
| `description` | str | No | `None` | Test description |
155-
| `column_name` | str | No | `None` | Column being tested |
156-
| `tags`, `owners`, `metadata`, `quality_dimension`, `skip` | - | No | - | Same as `@boolean_test` |
152+
| `severity`, `description`, `column_name`, `tags`, `owners`, `metadata`, `quality_dimension`, `skip` | - | No | - | Same as `@boolean_test` |
157153

158154
### Example
159155

@@ -199,9 +195,7 @@ def test_function(df: pd.DataFrame) -> Sized:
199195
| `name` | str | Yes | - | Test name |
200196
| `min` | int | No | `None` | Minimum expected row count (inclusive) |
201197
| `max` | int | No | `None` | Maximum expected row count (inclusive) |
202-
| `severity` | str | No | `"ERROR"` | Test severity |
203-
| `description` | str | No | `None` | Test description |
204-
| `tags`, `owners`, `metadata`, `skip` | - | No | - | Same as `@boolean_test` |
198+
| `severity`, `description`, `tags`, `owners`, `metadata`, `skip` | - | No | - | Same as `@boolean_test` |
205199

206200
### Example
207201

@@ -214,7 +208,7 @@ def test_function(df: pd.DataFrame) -> Sized:
214208
description="Validate user count is within expected range",
215209
)
216210
def get_users_df(df: pd.DataFrame) -> pd.DataFrame:
217-
"""Return the dataframe - decorator calls len() on it."""
211+
"""Return the DataFrame; the decorator calls len() on it."""
218212
return df
219213
```
220214

@@ -240,6 +234,6 @@ All decorators support these common parameters:
240234
## Related Documentation
241235

242236
- [Quickstart](/python-sdk/quickstart) - Get started with test decorators
243-
- [Sending Data](/python-sdk/guides/sending-data) - Learn how to send test results
244-
- [Best Practices](/python-sdk/guides/best-practices) - Best practices for using the SDK
237+
- [API Reference](/python-sdk/api-reference/overview) - Overview of the SDK API
238+
- [Table Assets](/python-sdk/api-reference/table-assets) - Register tables and views in your data warehouse
245239

docs/python-sdk/api-reference/test-executions.mdx

Lines changed: 0 additions & 156 deletions
This file was deleted.

0 commit comments

Comments
 (0)