Skip to content

Commit b40bb7a

Browse files
authored
docs: improve taxonomy method visibility and quick references (#80)
resolves: trufnetwork/truf-network#1126
1 parent a01f9ec commit b40bb7a

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,13 @@ client.set_taxonomy(
218218
},
219219
start_date=current_timestamp
220220
)
221+
222+
# Get taxonomy information for the composed stream
223+
taxonomy = client.describe_taxonomy(tech_innovation_index)
224+
if taxonomy:
225+
print(f"Stream: {taxonomy['stream_id']}")
226+
for child in taxonomy['child_streams']:
227+
print(f" Child: {child.stream['stream_id']}, Weight: {child.weight}")
221228
```
222229

223230
### Stream Visibility and Access Control
@@ -251,6 +258,26 @@ client.destroy_stream(stream_id)
251258

252259
For a comprehensive example demonstrating the full stream lifecycle, refer to our [Complex Example](./examples/complex_example/README.md).
253260

261+
## Quick Reference
262+
263+
### Common Operations
264+
265+
| Operation | Method |
266+
|-----------|--------|
267+
| Deploy primitive stream | `client.deploy_stream(stream_id, STREAM_TYPE_PRIMITIVE)` |
268+
| Deploy composed stream | `client.deploy_stream(stream_id, STREAM_TYPE_COMPOSED)` |
269+
| Insert records | `client.insert_record(stream_id, {"date": timestamp, "value": value})` |
270+
| Get stream data | `client.get_records(stream_id, date_from=from_ts, date_to=to_ts)` |
271+
| Set stream taxonomy | `client.set_taxonomy(stream_id, {child_id: weight}, start_date)` |
272+
| Get stream taxonomy | `client.describe_taxonomy(stream_id, latest_version=True)` |
273+
| Destroy stream | `client.destroy_stream(stream_id)` |
274+
275+
### Key Constants
276+
277+
- `STREAM_TYPE_PRIMITIVE` - Raw data streams
278+
- `STREAM_TYPE_COMPOSED` - Aggregated streams with taxonomy
279+
- `TaxonomyDetails` - Taxonomy information with child streams and weights
280+
254281
## Local Node Testing and Development
255282

256283
This section describes how to set up a local development environment, including running a local node for testing and running the SDK's test suite.

docs/api-reference.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,8 @@ tx_hash = client.set_taxonomy(
401401
)
402402
```
403403

404-
### `client.describe_taxonomy(stream_id: str, latest_version: bool = True) -> TaxonomyDetails | None`
405-
Get taxonomy structure of a composed stream.
404+
### `client.describe_taxonomy(stream_id: str, latest_version: bool = True) -> TaxonomyDetails | None` 🔍
405+
Get taxonomy structure of a composed stream. This is the primary method for discovering how composed streams aggregate their child streams and understanding composition relationships.
406406

407407
#### Parameters
408408
- `stream_id: str` - Composed stream identifier
@@ -416,11 +416,24 @@ Get taxonomy structure of a composed stream.
416416

417417
#### Example
418418
```python
419+
# Get taxonomy information for a composed stream
419420
taxonomy = client.describe_taxonomy(composed_stream_id)
420421
if taxonomy:
421422
print(f"Stream: {taxonomy['stream_id']}")
423+
total_weight = 0
422424
for child in taxonomy['child_streams']:
423425
print(f" Child: {child.stream['stream_id']}, Weight: {child.weight}")
426+
total_weight += child.weight
427+
print(f"Total weight: {total_weight}")
428+
else:
429+
print("No taxonomy found for this stream")
430+
431+
# Example: Validate taxonomy weights sum to 1.0
432+
if taxonomy:
433+
weights = [child.weight for child in taxonomy['child_streams']]
434+
total_weight = sum(weights)
435+
if abs(total_weight - 1.0) > 0.001: # Allow small floating point differences
436+
print(f"Warning: Weights don't sum to 1.0 (actual: {total_weight})")
424437
```
425438

426439
### `client.allow_compose_stream(stream_id: str, wait: bool = True) -> str`

0 commit comments

Comments
 (0)