unitysvc-services 0.1.4__tar.gz → 0.1.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. {unitysvc_services-0.1.4/src/unitysvc_services.egg-info → unitysvc_services-0.1.5}/PKG-INFO +40 -33
  2. {unitysvc_services-0.1.4 → unitysvc_services-0.1.5}/README.md +39 -32
  3. {unitysvc_services-0.1.4 → unitysvc_services-0.1.5}/docs/api-reference.md +201 -0
  4. {unitysvc_services-0.1.4 → unitysvc_services-0.1.5}/docs/cli-reference.md +197 -59
  5. unitysvc_services-0.1.5/docs/code-examples.md +731 -0
  6. unitysvc_services-0.1.5/docs/documenting-services.md +643 -0
  7. {unitysvc_services-0.1.4 → unitysvc_services-0.1.5}/docs/getting-started.md +29 -25
  8. {unitysvc_services-0.1.4 → unitysvc_services-0.1.5}/docs/workflows.md +39 -37
  9. {unitysvc_services-0.1.4 → unitysvc_services-0.1.5}/pyproject.toml +2 -1
  10. {unitysvc_services-0.1.4 → unitysvc_services-0.1.5}/src/unitysvc_services/api.py +58 -15
  11. {unitysvc_services-0.1.4 → unitysvc_services-0.1.5}/src/unitysvc_services/cli.py +2 -1
  12. {unitysvc_services-0.1.4 → unitysvc_services-0.1.5}/src/unitysvc_services/models/base.py +12 -0
  13. {unitysvc_services-0.1.4 → unitysvc_services-0.1.5}/src/unitysvc_services/populate.py +18 -0
  14. {unitysvc_services-0.1.4 → unitysvc_services-0.1.5}/src/unitysvc_services/publisher.py +329 -199
  15. unitysvc_services-0.1.5/src/unitysvc_services/query.py +682 -0
  16. unitysvc_services-0.1.5/src/unitysvc_services/test.py +769 -0
  17. {unitysvc_services-0.1.4 → unitysvc_services-0.1.5}/src/unitysvc_services/utils.py +53 -0
  18. {unitysvc_services-0.1.4 → unitysvc_services-0.1.5}/src/unitysvc_services/validator.py +19 -7
  19. {unitysvc_services-0.1.4 → unitysvc_services-0.1.5/src/unitysvc_services.egg-info}/PKG-INFO +40 -33
  20. {unitysvc_services-0.1.4 → unitysvc_services-0.1.5}/src/unitysvc_services.egg-info/SOURCES.txt +3 -0
  21. {unitysvc_services-0.1.4 → unitysvc_services-0.1.5}/src/unitysvc_services.egg-info/entry_points.txt +1 -0
  22. {unitysvc_services-0.1.4 → unitysvc_services-0.1.5}/tests/test_validator.py +15 -14
  23. unitysvc_services-0.1.4/src/unitysvc_services/query.py +0 -674
  24. {unitysvc_services-0.1.4 → unitysvc_services-0.1.5}/CONTRIBUTING.md +0 -0
  25. {unitysvc_services-0.1.4 → unitysvc_services-0.1.5}/HISTORY.md +0 -0
  26. {unitysvc_services-0.1.4 → unitysvc_services-0.1.5}/LICENSE +0 -0
  27. {unitysvc_services-0.1.4 → unitysvc_services-0.1.5}/MANIFEST.in +0 -0
  28. {unitysvc_services-0.1.4 → unitysvc_services-0.1.5}/docs/contributing.md +0 -0
  29. {unitysvc_services-0.1.4 → unitysvc_services-0.1.5}/docs/data-structure.md +0 -0
  30. {unitysvc_services-0.1.4 → unitysvc_services-0.1.5}/docs/development.md +0 -0
  31. {unitysvc_services-0.1.4 → unitysvc_services-0.1.5}/docs/file-schemas.md +0 -0
  32. {unitysvc_services-0.1.4 → unitysvc_services-0.1.5}/docs/index.md +0 -0
  33. {unitysvc_services-0.1.4 → unitysvc_services-0.1.5}/docs/installation.md +0 -0
  34. {unitysvc_services-0.1.4 → unitysvc_services-0.1.5}/docs/usage.md +0 -0
  35. {unitysvc_services-0.1.4 → unitysvc_services-0.1.5}/setup.cfg +0 -0
  36. {unitysvc_services-0.1.4 → unitysvc_services-0.1.5}/src/unitysvc_services/__init__.py +0 -0
  37. {unitysvc_services-0.1.4 → unitysvc_services-0.1.5}/src/unitysvc_services/format_data.py +0 -0
  38. {unitysvc_services-0.1.4 → unitysvc_services-0.1.5}/src/unitysvc_services/list.py +0 -0
  39. {unitysvc_services-0.1.4 → unitysvc_services-0.1.5}/src/unitysvc_services/models/__init__.py +0 -0
  40. {unitysvc_services-0.1.4 → unitysvc_services-0.1.5}/src/unitysvc_services/models/listing_v1.py +0 -0
  41. {unitysvc_services-0.1.4 → unitysvc_services-0.1.5}/src/unitysvc_services/models/provider_v1.py +0 -0
  42. {unitysvc_services-0.1.4 → unitysvc_services-0.1.5}/src/unitysvc_services/models/seller_v1.py +0 -0
  43. {unitysvc_services-0.1.4 → unitysvc_services-0.1.5}/src/unitysvc_services/models/service_v1.py +0 -0
  44. {unitysvc_services-0.1.4 → unitysvc_services-0.1.5}/src/unitysvc_services/py.typed +0 -0
  45. {unitysvc_services-0.1.4 → unitysvc_services-0.1.5}/src/unitysvc_services/scaffold.py +0 -0
  46. {unitysvc_services-0.1.4 → unitysvc_services-0.1.5}/src/unitysvc_services/update.py +0 -0
  47. {unitysvc_services-0.1.4 → unitysvc_services-0.1.5}/src/unitysvc_services.egg-info/dependency_links.txt +0 -0
  48. {unitysvc_services-0.1.4 → unitysvc_services-0.1.5}/src/unitysvc_services.egg-info/requires.txt +0 -0
  49. {unitysvc_services-0.1.4 → unitysvc_services-0.1.5}/src/unitysvc_services.egg-info/top_level.txt +0 -0
  50. {unitysvc_services-0.1.4 → unitysvc_services-0.1.5}/tests/__init__.py +0 -0
  51. {unitysvc_services-0.1.4 → unitysvc_services-0.1.5}/tests/example_data/README.md +0 -0
  52. {unitysvc_services-0.1.4 → unitysvc_services-0.1.5}/tests/example_data/provider1/README.md +0 -0
  53. {unitysvc_services-0.1.4 → unitysvc_services-0.1.5}/tests/example_data/provider1/provider.toml +0 -0
  54. {unitysvc_services-0.1.4 → unitysvc_services-0.1.5}/tests/example_data/provider1/services/service1/code-example.md +0 -0
  55. {unitysvc_services-0.1.4 → unitysvc_services-0.1.5}/tests/example_data/provider1/services/service1/service.toml +0 -0
  56. {unitysvc_services-0.1.4 → unitysvc_services-0.1.5}/tests/example_data/provider1/services/service1/svcreseller.toml +0 -0
  57. {unitysvc_services-0.1.4 → unitysvc_services-0.1.5}/tests/example_data/provider1/terms-of-service.md +0 -0
  58. {unitysvc_services-0.1.4 → unitysvc_services-0.1.5}/tests/example_data/provider2/README.md +0 -0
  59. {unitysvc_services-0.1.4 → unitysvc_services-0.1.5}/tests/example_data/provider2/provider.json +0 -0
  60. {unitysvc_services-0.1.4 → unitysvc_services-0.1.5}/tests/example_data/provider2/services/service2/code-example.md +0 -0
  61. {unitysvc_services-0.1.4 → unitysvc_services-0.1.5}/tests/example_data/provider2/services/service2/service.json +0 -0
  62. {unitysvc_services-0.1.4 → unitysvc_services-0.1.5}/tests/example_data/provider2/services/service2/svcreseller.json +0 -0
  63. {unitysvc_services-0.1.4 → unitysvc_services-0.1.5}/tests/example_data/provider2/terms-of-service.md +0 -0
  64. {unitysvc_services-0.1.4 → unitysvc_services-0.1.5}/tests/example_data/seller.json +0 -0
  65. {unitysvc_services-0.1.4 → unitysvc_services-0.1.5}/tests/test_utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: unitysvc-services
3
- Version: 0.1.4
3
+ Version: 0.1.5
4
4
  Summary: SDK for digital service providers on UnitySVC
5
5
  Author-email: Bo Peng <bo.peng@unitysvc.com>
6
6
  Maintainer-email: Bo Peng <bo.peng@unitysvc.com>
@@ -40,22 +40,23 @@ Requires-Dist: mkdocs-material; extra == "docs"
40
40
  Requires-Dist: mkdocs-autorefs; extra == "docs"
41
41
  Dynamic: license-file
42
42
 
43
- # UnitySVC Provider SDK
43
+ # UnitySVC Services SDK
44
44
 
45
45
  ![PyPI version](https://img.shields.io/pypi/v/unitysvc-services.svg)
46
46
  [![Documentation Status](https://readthedocs.org/projects/unitysvc-services/badge/?version=latest)](https://unitysvc-services.readthedocs.io/en/latest/?version=latest)
47
47
 
48
- Client library and CLI tools for digital service providers to interact with the UnitySVC platform.
48
+ Client library and CLI tools for sellers and providers of digital service to interact with the UnitySVC platform.
49
49
 
50
50
  **📚 [Full Documentation](https://unitysvc-services.readthedocs.io)** | **🚀 [Getting Started](https://unitysvc-services.readthedocs.io/en/latest/getting-started/)** | **📖 [CLI Reference](https://unitysvc-services.readthedocs.io/en/latest/cli-reference/)**
51
51
 
52
52
  ## Overview
53
53
 
54
- UnitySVC Provider SDK enables digital service providers to manage their service offerings through a **local-first, version-controlled workflow**:
54
+ UnitySVC Services SDK enables digital service sellers and providers to manage their service offerings through a **local-first, version-controlled workflow**:
55
55
 
56
56
  - **Define** service data using schema-validated files (JSON/TOML)
57
57
  - **Manage** everything locally in git-controlled directories
58
- - **Validate** data against schemas before publishing
58
+ - **Validate** data against schemas
59
+ - **Test** code examples using provider credentials
59
60
  - **Publish** to UnitySVC platform when ready
60
61
  - **Automate** with populate scripts for dynamic catalogs
61
62
 
@@ -67,31 +68,34 @@ pip install unitysvc-services
67
68
 
68
69
  Requires Python 3.11+
69
70
 
71
+ **CLI Alias:** The command `unitysvc_services` can also be invoked using the shorter alias `usvc`.
72
+
70
73
  ## Quick Example
71
74
 
72
75
  ```bash
73
- # Initialize provider and service
74
- unitysvc_services init provider my-provider
75
- unitysvc_services init offering my-service
76
- unitysvc_services init seller my-marketplace
76
+ # Initialize provider and service (using short alias 'usvc')
77
+ usvc init provider my-provider
78
+ usvc init offering my-service
79
+ usvc init seller my-marketplace
77
80
 
78
81
  # Validate and format
79
- unitysvc_services validate
80
- unitysvc_services format
82
+ usvc validate
83
+ usvc format
84
+
85
+ # Test code examples with upstream credentials
86
+ usvc test list --provider fireworks
87
+ usvc test run --provider fireworks --services "llama*"
88
+
89
+ # if you write a script to manage services
90
+ usvc populate
81
91
 
82
92
  # Publish to platform (publishes all: sellers, providers, offerings, listings)
83
93
  export UNITYSVC_BASE_URL="https://api.unitysvc.com/api/v1"
84
94
  export UNITYSVC_API_KEY="your-api-key"
85
- unitysvc_services publish
86
-
87
- # Or publish specific types only
88
- unitysvc_services publish providers
89
-
90
- # Verify with default fields
91
- unitysvc_services query offerings
95
+ usvc publish
92
96
 
93
- # Query with custom fields
94
- unitysvc_services query providers --fields id,name,contact_email
97
+ # Query unitysvc backend to verify data
98
+ usvc query providers --fields id,name,contact_email
95
99
  ```
96
100
 
97
101
  ## Key Features
@@ -108,13 +112,13 @@ unitysvc_services query providers --fields id,name,contact_email
108
112
  ### Manual Workflow (small catalogs)
109
113
 
110
114
  ```bash
111
- init → edit files → validate → format → publish → verify
115
+ init → edit files → validate → test → format → publish → verify
112
116
  ```
113
117
 
114
118
  ### Automated Workflow (large/dynamic catalogs)
115
119
 
116
120
  ```bash
117
- init provider → configure populate script → populate → validate → publish
121
+ init → configure populate script → populate → validate → publish
118
122
  ```
119
123
 
120
124
  See [Workflows Documentation](https://unitysvc-services.readthedocs.io/en/latest/workflows/) for details.
@@ -137,24 +141,27 @@ See [Data Structure Documentation](https://unitysvc-services.readthedocs.io/en/l
137
141
 
138
142
  ## CLI Commands
139
143
 
140
- | Command | Description |
141
- | ---------- | -------------------------------------- |
142
- | `init` | Initialize new data files from schemas |
143
- | `list` | List local data files |
144
- | `query` | Query backend API for published data |
145
- | `publish` | Publish data to backend |
146
- | `update` | Update local file fields |
147
- | `validate` | Validate data consistency |
148
- | `format` | Format data files |
149
- | `populate` | Execute provider populate scripts |
144
+ | Command | Description |
145
+ | ---------- | ------------------------------------------------ |
146
+ | `init` | Initialize new data files from schemas |
147
+ | `list` | List local data files |
148
+ | `query` | Query backend API for published data |
149
+ | `publish` | Publish data to backend |
150
+ | `update` | Update local file fields |
151
+ | `validate` | Validate data consistency |
152
+ | `format` | Format data files |
153
+ | `populate` | Execute provider populate scripts |
154
+ | `test` | Test code examples with upstream API credentials |
150
155
 
151
- Run `unitysvc_services --help` or see [CLI Reference](https://unitysvc-services.readthedocs.io/en/latest/cli-reference/) for complete documentation.
156
+ Run `usvc --help` or see [CLI Reference](https://unitysvc-services.readthedocs.io/en/latest/cli-reference/) for complete documentation.
152
157
 
153
158
  ## Documentation
154
159
 
155
160
  - **[Getting Started](https://unitysvc-services.readthedocs.io/en/latest/getting-started/)** - Installation and first steps
156
161
  - **[Data Structure](https://unitysvc-services.readthedocs.io/en/latest/data-structure/)** - File organization rules
157
162
  - **[Workflows](https://unitysvc-services.readthedocs.io/en/latest/workflows/)** - Manual and automated patterns
163
+ - **[Documenting Service Listings](https://unitysvc-services.readthedocs.io/en/latest/documenting-services/)** - Add documentation to services
164
+ - **[Creating Code Examples](https://unitysvc-services.readthedocs.io/en/latest/code-examples/)** - Develop and test code examples
158
165
  - **[CLI Reference](https://unitysvc-services.readthedocs.io/en/latest/cli-reference/)** - All commands and options
159
166
  - **[File Schemas](https://unitysvc-services.readthedocs.io/en/latest/file-schemas/)** - Schema specifications
160
167
  - **[Python API](https://unitysvc-services.readthedocs.io/en/latest/api-reference/)** - Programmatic usage
@@ -1,19 +1,20 @@
1
- # UnitySVC Provider SDK
1
+ # UnitySVC Services SDK
2
2
 
3
3
  ![PyPI version](https://img.shields.io/pypi/v/unitysvc-services.svg)
4
4
  [![Documentation Status](https://readthedocs.org/projects/unitysvc-services/badge/?version=latest)](https://unitysvc-services.readthedocs.io/en/latest/?version=latest)
5
5
 
6
- Client library and CLI tools for digital service providers to interact with the UnitySVC platform.
6
+ Client library and CLI tools for sellers and providers of digital service to interact with the UnitySVC platform.
7
7
 
8
8
  **📚 [Full Documentation](https://unitysvc-services.readthedocs.io)** | **🚀 [Getting Started](https://unitysvc-services.readthedocs.io/en/latest/getting-started/)** | **📖 [CLI Reference](https://unitysvc-services.readthedocs.io/en/latest/cli-reference/)**
9
9
 
10
10
  ## Overview
11
11
 
12
- UnitySVC Provider SDK enables digital service providers to manage their service offerings through a **local-first, version-controlled workflow**:
12
+ UnitySVC Services SDK enables digital service sellers and providers to manage their service offerings through a **local-first, version-controlled workflow**:
13
13
 
14
14
  - **Define** service data using schema-validated files (JSON/TOML)
15
15
  - **Manage** everything locally in git-controlled directories
16
- - **Validate** data against schemas before publishing
16
+ - **Validate** data against schemas
17
+ - **Test** code examples using provider credentials
17
18
  - **Publish** to UnitySVC platform when ready
18
19
  - **Automate** with populate scripts for dynamic catalogs
19
20
 
@@ -25,31 +26,34 @@ pip install unitysvc-services
25
26
 
26
27
  Requires Python 3.11+
27
28
 
29
+ **CLI Alias:** The command `unitysvc_services` can also be invoked using the shorter alias `usvc`.
30
+
28
31
  ## Quick Example
29
32
 
30
33
  ```bash
31
- # Initialize provider and service
32
- unitysvc_services init provider my-provider
33
- unitysvc_services init offering my-service
34
- unitysvc_services init seller my-marketplace
34
+ # Initialize provider and service (using short alias 'usvc')
35
+ usvc init provider my-provider
36
+ usvc init offering my-service
37
+ usvc init seller my-marketplace
35
38
 
36
39
  # Validate and format
37
- unitysvc_services validate
38
- unitysvc_services format
40
+ usvc validate
41
+ usvc format
42
+
43
+ # Test code examples with upstream credentials
44
+ usvc test list --provider fireworks
45
+ usvc test run --provider fireworks --services "llama*"
46
+
47
+ # if you write a script to manage services
48
+ usvc populate
39
49
 
40
50
  # Publish to platform (publishes all: sellers, providers, offerings, listings)
41
51
  export UNITYSVC_BASE_URL="https://api.unitysvc.com/api/v1"
42
52
  export UNITYSVC_API_KEY="your-api-key"
43
- unitysvc_services publish
44
-
45
- # Or publish specific types only
46
- unitysvc_services publish providers
47
-
48
- # Verify with default fields
49
- unitysvc_services query offerings
53
+ usvc publish
50
54
 
51
- # Query with custom fields
52
- unitysvc_services query providers --fields id,name,contact_email
55
+ # Query unitysvc backend to verify data
56
+ usvc query providers --fields id,name,contact_email
53
57
  ```
54
58
 
55
59
  ## Key Features
@@ -66,13 +70,13 @@ unitysvc_services query providers --fields id,name,contact_email
66
70
  ### Manual Workflow (small catalogs)
67
71
 
68
72
  ```bash
69
- init → edit files → validate → format → publish → verify
73
+ init → edit files → validate → test → format → publish → verify
70
74
  ```
71
75
 
72
76
  ### Automated Workflow (large/dynamic catalogs)
73
77
 
74
78
  ```bash
75
- init provider → configure populate script → populate → validate → publish
79
+ init → configure populate script → populate → validate → publish
76
80
  ```
77
81
 
78
82
  See [Workflows Documentation](https://unitysvc-services.readthedocs.io/en/latest/workflows/) for details.
@@ -95,24 +99,27 @@ See [Data Structure Documentation](https://unitysvc-services.readthedocs.io/en/l
95
99
 
96
100
  ## CLI Commands
97
101
 
98
- | Command | Description |
99
- | ---------- | -------------------------------------- |
100
- | `init` | Initialize new data files from schemas |
101
- | `list` | List local data files |
102
- | `query` | Query backend API for published data |
103
- | `publish` | Publish data to backend |
104
- | `update` | Update local file fields |
105
- | `validate` | Validate data consistency |
106
- | `format` | Format data files |
107
- | `populate` | Execute provider populate scripts |
102
+ | Command | Description |
103
+ | ---------- | ------------------------------------------------ |
104
+ | `init` | Initialize new data files from schemas |
105
+ | `list` | List local data files |
106
+ | `query` | Query backend API for published data |
107
+ | `publish` | Publish data to backend |
108
+ | `update` | Update local file fields |
109
+ | `validate` | Validate data consistency |
110
+ | `format` | Format data files |
111
+ | `populate` | Execute provider populate scripts |
112
+ | `test` | Test code examples with upstream API credentials |
108
113
 
109
- Run `unitysvc_services --help` or see [CLI Reference](https://unitysvc-services.readthedocs.io/en/latest/cli-reference/) for complete documentation.
114
+ Run `usvc --help` or see [CLI Reference](https://unitysvc-services.readthedocs.io/en/latest/cli-reference/) for complete documentation.
110
115
 
111
116
  ## Documentation
112
117
 
113
118
  - **[Getting Started](https://unitysvc-services.readthedocs.io/en/latest/getting-started/)** - Installation and first steps
114
119
  - **[Data Structure](https://unitysvc-services.readthedocs.io/en/latest/data-structure/)** - File organization rules
115
120
  - **[Workflows](https://unitysvc-services.readthedocs.io/en/latest/workflows/)** - Manual and automated patterns
121
+ - **[Documenting Service Listings](https://unitysvc-services.readthedocs.io/en/latest/documenting-services/)** - Add documentation to services
122
+ - **[Creating Code Examples](https://unitysvc-services.readthedocs.io/en/latest/code-examples/)** - Develop and test code examples
116
123
  - **[CLI Reference](https://unitysvc-services.readthedocs.io/en/latest/cli-reference/)** - All commands and options
117
124
  - **[File Schemas](https://unitysvc-services.readthedocs.io/en/latest/file-schemas/)** - Schema specifications
118
125
  - **[Python API](https://unitysvc-services.readthedocs.io/en/latest/api-reference/)** - Programmatic usage
@@ -140,6 +140,145 @@ else:
140
140
 
141
141
  - `tuple[Path, str, dict] | None`: (file_path, format, data) or None if not found
142
142
 
143
+ #### resolve_provider_name()
144
+
145
+ Resolve the provider name from a file path.
146
+
147
+ ```python
148
+ from pathlib import Path
149
+ from unitysvc_services.utils import resolve_provider_name
150
+
151
+ provider_name = resolve_provider_name(
152
+ Path("data/fireworks/services/llama-3-1/listing.json")
153
+ )
154
+ # Returns: "fireworks"
155
+ ```
156
+
157
+ **Parameters:**
158
+
159
+ - `file_path` (Path): Path to the service offering or listing file
160
+
161
+ **Returns:**
162
+
163
+ - `str | None`: Provider name if found, None otherwise
164
+
165
+ **How it works:**
166
+
167
+ - Checks if file is under a "services" directory
168
+ - Provider name is the directory before "services"
169
+ - Validates by looking for provider data file in that directory
170
+ - Returns the name from the provider file if found
171
+
172
+ #### resolve_service_name_for_listing()
173
+
174
+ Resolve the service name for a listing file.
175
+
176
+ ```python
177
+ from pathlib import Path
178
+ from unitysvc_services.utils import (
179
+ load_data_file,
180
+ resolve_service_name_for_listing
181
+ )
182
+
183
+ listing_file = Path("data/fireworks/services/llama-3-1/listing.json")
184
+ listing_data, _ = load_data_file(listing_file)
185
+
186
+ service_name = resolve_service_name_for_listing(listing_file, listing_data)
187
+ # Returns: service name from listing or from co-located service.json
188
+ ```
189
+
190
+ **Parameters:**
191
+
192
+ - `listing_file` (Path): Path to the listing file
193
+ - `listing_data` (dict): Listing data dictionary
194
+
195
+ **Returns:**
196
+
197
+ - `str | None`: Service name if found, None otherwise
198
+
199
+ **Resolution Rules:**
200
+
201
+ 1. If `service_name` is defined in listing_data, return it
202
+ 2. Otherwise, find the only service offering in the same directory and return its name
203
+ 3. Return None if multiple or no service offerings found
204
+
205
+ #### convert_convenience_fields_to_documents()
206
+
207
+ Convert convenience fields (logo, terms_of_service) to Document objects.
208
+
209
+ ```python
210
+ from pathlib import Path
211
+ from unitysvc_services.utils import convert_convenience_fields_to_documents
212
+
213
+ data = {
214
+ "logo": "assets/logo.png",
215
+ "terms_of_service": "https://example.com/terms",
216
+ "documents": []
217
+ }
218
+
219
+ updated_data = convert_convenience_fields_to_documents(
220
+ data,
221
+ base_path=Path("/data/provider")
222
+ )
223
+ # logo and terms_of_service fields are removed
224
+ # Corresponding Document objects added to documents list
225
+ ```
226
+
227
+ **Parameters:**
228
+
229
+ - `data` (dict): Data dictionary containing potential convenience fields
230
+ - `base_path` (Path): Base path for resolving relative file paths
231
+ - `logo_field` (str): Name of the logo field (default: "logo")
232
+ - `terms_field` (str | None): Name of the terms field (default: "terms_of_service", None to skip)
233
+
234
+ **Returns:**
235
+
236
+ - `dict`: Updated data dictionary with convenience fields converted to documents list
237
+
238
+ **What it does:**
239
+
240
+ - Converts file paths or URLs to proper Document structures
241
+ - Automatically determines MIME types from file extensions
242
+ - Removes convenience fields after conversion
243
+ - Adds Document objects to the documents list
244
+
245
+ #### render_template_file()
246
+
247
+ Render a Jinja2 template file and return content and new filename.
248
+
249
+ ```python
250
+ from pathlib import Path
251
+ from unitysvc_services.utils import render_template_file
252
+
253
+ rendered_content, new_filename = render_template_file(
254
+ Path("test.py.j2"),
255
+ listing={"service_name": "gpt-4"},
256
+ offering={"name": "gpt-4-turbo"},
257
+ provider={"provider_name": "openai"},
258
+ seller={"seller_name": "marketplace"}
259
+ )
260
+ # rendered_content: Template rendered with data
261
+ # new_filename: "test.py" (without .j2 extension)
262
+ ```
263
+
264
+ **Parameters:**
265
+
266
+ - `file_path` (Path): Path to the file (may or may not be a .j2 template)
267
+ - `listing` (dict, optional): Listing data for template rendering
268
+ - `offering` (dict, optional): Offering data for template rendering
269
+ - `provider` (dict, optional): Provider data for template rendering
270
+ - `seller` (dict, optional): Seller data for template rendering
271
+
272
+ **Returns:**
273
+
274
+ - `tuple[str, str]`: (rendered_content, new_filename_without_j2)
275
+
276
+ **Behavior:**
277
+
278
+ - If file ends with `.j2`: Renders as Jinja2 template and strips `.j2` from filename
279
+ - If file does not end with `.j2`: Returns content as-is with original filename
280
+ - All template variables default to empty dict if not provided
281
+
143
282
  ### unitysvc_services.cli
144
283
 
145
284
  Main CLI application built with Typer.
@@ -156,6 +295,7 @@ from unitysvc_services.cli import app
156
295
  # - validate: Validate data
157
296
  # - format: Format files
158
297
  # - populate: Run populate scripts
298
+ # - test: Test code examples with upstream credentials
159
299
  ```
160
300
 
161
301
  ### unitysvc_services.publisher
@@ -319,6 +459,65 @@ for provider, success, output in results:
319
459
 
320
460
  - `list[tuple[str, bool, str]]`: List of (provider_name, success, output)
321
461
 
462
+ ### unitysvc_services.test
463
+
464
+ Code example testing operations.
465
+
466
+ #### list_code_examples()
467
+
468
+ List available code examples from listing files.
469
+
470
+ ```python
471
+ from pathlib import Path
472
+ from unitysvc_services.test import list_code_examples
473
+
474
+ # This is typically called via CLI, but can be used programmatically
475
+ # Note: This function uses Typer and is designed for CLI use
476
+ ```
477
+
478
+ **Functionality:**
479
+
480
+ - Scans for listing files (schema: listing_v1)
481
+ - Extracts documents with category = "code_examples"
482
+ - Displays results in table format with file paths
483
+ - Supports filtering by provider and service patterns
484
+
485
+ #### run_tests()
486
+
487
+ Execute code examples with upstream credentials.
488
+
489
+ ```python
490
+ from pathlib import Path
491
+ from unitysvc_services.test import run
492
+
493
+ # This is typically called via CLI, but can be used programmatically
494
+ # Note: This function uses Typer and is designed for CLI use
495
+ ```
496
+
497
+ **Functionality:**
498
+
499
+ - Discovers code examples from listing files
500
+ - Loads related data (offering, provider, seller)
501
+ - Renders Jinja2 templates with context data
502
+ - Executes code with appropriate interpreter
503
+ - Validates output based on exit code and `expect` field
504
+ - Saves failed test content for debugging
505
+
506
+ **Test Execution:**
507
+
508
+ 1. Template rendering with listing, offering, provider, seller data
509
+ 2. Environment variable setup (API_KEY, API_ENDPOINT)
510
+ 3. Interpreter detection (.py → python3, .js → node, .sh → bash)
511
+ 4. Script execution with timeout
512
+ 5. Output validation (exit code + optional expect string)
513
+
514
+ **Test Pass Criteria:**
515
+
516
+ - Exit code is 0 AND
517
+ - If `expect` field exists: expected string found in stdout
518
+
519
+ See [Creating Code Examples](https://unitysvc-services.readthedocs.io/en/latest/code-examples/) guide for detailed workflow.
520
+
322
521
  ## Pydantic Models
323
522
 
324
523
  ### Provider
@@ -524,5 +723,7 @@ def get_service(name: str, data_dir: Path = Path("data")) -> dict[str, Any] | No
524
723
  ## See Also
525
724
 
526
725
  - [CLI Reference](cli-reference.md) - Command-line interface
726
+ - [Documenting Service Listings](documenting-services.md) - Add documentation to services
727
+ - [Creating Code Examples](code-examples.md) - Develop and test code examples
527
728
  - [File Schemas](file-schemas.md) - Data schema specifications
528
729
  - [Workflows](workflows.md) - Usage patterns and examples