python-postman 0.8.0__tar.gz → 0.9.0__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.
- {python_postman-0.8.0 → python_postman-0.9.0}/PKG-INFO +35 -36
- {python_postman-0.8.0 → python_postman-0.9.0}/README.md +32 -34
- python_postman-0.9.0/coverage.json +1 -0
- python_postman-0.9.0/docs/README.md +456 -0
- python_postman-0.9.0/docs/architecture/execution-layer.md +555 -0
- python_postman-0.9.0/docs/architecture/layer-interaction.md +597 -0
- python_postman-0.9.0/docs/architecture/model-layer.md +501 -0
- python_postman-0.9.0/docs/architecture/overview.md +186 -0
- python_postman-0.9.0/docs/examples/description-usage.py +434 -0
- python_postman-0.9.0/docs/examples/generate-documentation.py +439 -0
- python_postman-0.9.0/docs/examples/parse-inspect-modify-execute.py +325 -0
- python_postman-0.9.0/docs/examples/variable-introspection.py +313 -0
- python_postman-0.9.0/docs/guides/decision-tree.md +587 -0
- python_postman-0.9.0/docs/guides/description-fields.md +425 -0
- python_postman-0.9.0/docs/guides/optional-dependencies.md +685 -0
- python_postman-0.9.0/docs/guides/troubleshooting.md +810 -0
- python_postman-0.9.0/docs/guides/variable-scoping.md +471 -0
- python_postman-0.9.0/examples/auth_resolution_example.py +186 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/examples/basic_execution.py +1 -1
- python_postman-0.9.0/examples/cftc_execution_example.py +240 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/examples/complete_workflow.py +1 -1
- python_postman-0.9.0/examples/multi_collection_execution.py +185 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/examples/path_parameters_example.py +2 -2
- python_postman-0.9.0/examples/projects/README.md +48 -0
- python_postman-0.9.0/examples/projects/microservices-testing/README.md +48 -0
- python_postman-0.9.0/examples/projects/microservices-testing/collections/auth-service.json +55 -0
- python_postman-0.9.0/examples/projects/microservices-testing/collections/order-service.json +60 -0
- python_postman-0.9.0/examples/projects/microservices-testing/collections/user-service.json +59 -0
- python_postman-0.9.0/examples/projects/microservices-testing/environments/microservices.json +30 -0
- python_postman-0.9.0/examples/projects/microservices-testing/main.py +73 -0
- python_postman-0.9.0/examples/projects/rest-api-testing/README.md +63 -0
- python_postman-0.9.0/examples/projects/rest-api-testing/collections/rest-api.json +110 -0
- python_postman-0.9.0/examples/projects/rest-api-testing/environments/dev.json +15 -0
- python_postman-0.9.0/examples/projects/rest-api-testing/environments/prod.json +15 -0
- python_postman-0.9.0/examples/projects/rest-api-testing/main.py +48 -0
- python_postman-0.9.0/examples/projects/rest-api-testing/requirements.txt +2 -0
- python_postman-0.9.0/examples/projects/rest-api-testing/tests/test_rest_api.py +39 -0
- python_postman-0.9.0/examples/request_convenience_methods.py +175 -0
- python_postman-0.9.0/examples/search_example.py +113 -0
- python_postman-0.9.0/examples/statistics_example.py +92 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/examples/synchronous_execution.py +3 -3
- {python_postman-0.8.0 → python_postman-0.9.0}/pyproject.toml +7 -5
- {python_postman-0.8.0 → python_postman-0.9.0}/python_postman/__init__.py +46 -5
- {python_postman-0.8.0 → python_postman-0.9.0}/python_postman/exceptions/__init__.py +2 -0
- python_postman-0.9.0/python_postman/exceptions/schema_error.py +35 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/python_postman/execution/__init__.py +4 -4
- {python_postman-0.8.0 → python_postman-0.9.0}/python_postman/execution/executor.py +1 -1
- {python_postman-0.8.0 → python_postman-0.9.0}/python_postman/execution/results.py +9 -9
- {python_postman-0.8.0 → python_postman-0.9.0}/python_postman/execution/script_runner.py +9 -9
- python_postman-0.9.0/python_postman/introspection/__init__.py +14 -0
- python_postman-0.9.0/python_postman/introspection/auth_resolver.py +135 -0
- python_postman-0.9.0/python_postman/introspection/variable_tracer.py +475 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/python_postman/models/__init__.py +9 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/python_postman/models/auth.py +34 -2
- {python_postman-0.8.0 → python_postman-0.9.0}/python_postman/models/collection.py +86 -14
- python_postman-0.9.0/python_postman/models/cookie.py +495 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/python_postman/models/folder.py +38 -2
- python_postman-0.9.0/python_postman/models/item.py +232 -0
- python_postman-0.9.0/python_postman/models/request.py +599 -0
- python_postman-0.9.0/python_postman/models/response.py +345 -0
- python_postman-0.9.0/python_postman/models/schema.py +144 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/python_postman/models/url.py +29 -3
- python_postman-0.9.0/python_postman/search/__init__.py +7 -0
- python_postman-0.9.0/python_postman/search/query.py +285 -0
- python_postman-0.9.0/python_postman/statistics/__init__.py +7 -0
- python_postman-0.9.0/python_postman/statistics/collector.py +327 -0
- python_postman-0.9.0/python_postman/types/__init__.py +13 -0
- python_postman-0.9.0/python_postman/types/auth_types.py +41 -0
- python_postman-0.9.0/python_postman/types/http_methods.py +39 -0
- python_postman-0.9.0/test_execution_summary.md +459 -0
- python_postman-0.9.0/tests/execution_tests/CFTC_TEST_SUMMARY.md +342 -0
- python_postman-0.9.0/tests/execution_tests/INDEX.md +239 -0
- python_postman-0.9.0/tests/execution_tests/QUICK_START_CFTC.md +127 -0
- python_postman-0.9.0/tests/execution_tests/README_CFTC_TESTS.md +357 -0
- python_postman-0.9.0/tests/execution_tests/example_cftc_usage.py +265 -0
- python_postman-0.9.0/tests/execution_tests/test_cftc_comprehensive.py +839 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/tests/test_auth.py +12 -18
- python_postman-0.9.0/tests/test_auth_resolver.py +561 -0
- python_postman-0.9.0/tests/test_cookie.py +574 -0
- python_postman-0.9.0/tests/test_description_fields.py +389 -0
- python_postman-0.9.0/tests/test_edge_cases.py +972 -0
- python_postman-0.9.0/tests/test_edge_cases.py.bak +963 -0
- python_postman-0.9.0/tests/test_edge_cases_summary.md +121 -0
- python_postman-0.9.0/tests/test_execution_reporter.py +268 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/tests/test_executor.py +29 -22
- {python_postman-0.8.0 → python_postman-0.9.0}/tests/test_imports.py +6 -6
- {python_postman-0.8.0 → python_postman-0.9.0}/tests/test_integration.py +8 -8
- python_postman-0.9.0/tests/test_item_clarity.py +221 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/tests/test_parser.py +33 -10
- python_postman-0.9.0/tests/test_request_convenience.py +538 -0
- python_postman-0.9.0/tests/test_request_responses.py +309 -0
- python_postman-0.9.0/tests/test_response.py +485 -0
- python_postman-0.9.0/tests/test_response_cookies.py +245 -0
- python_postman-0.9.0/tests/test_schema.py +289 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/tests/test_script_runner.py +4 -4
- python_postman-0.9.0/tests/test_search.py +396 -0
- python_postman-0.9.0/tests/test_statistics.py +416 -0
- python_postman-0.9.0/tests/test_type_safety.py +192 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/tests/test_url.py +15 -7
- python_postman-0.9.0/tests/test_variable_tracer.py +522 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/uv.lock +5 -5
- python_postman-0.8.0/python_postman/models/item.py +0 -44
- python_postman-0.8.0/python_postman/models/request.py +0 -319
- python_postman-0.8.0/tests/test_execution_integration.py +0 -1049
- python_postman-0.8.0/tests/test_response.py +0 -306
- {python_postman-0.8.0 → python_postman-0.9.0}/.github/workflows/python-publish.yml +0 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/.gitignore +0 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/LICENSE +0 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/examples/README.md +0 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/examples/advanced_execution.py +0 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/examples/authentication_examples.py +0 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/examples/usage_patterns.py +0 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/examples/variable_examples.py +0 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/python_postman/exceptions/base.py +0 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/python_postman/exceptions/file_error.py +0 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/python_postman/exceptions/parse_error.py +0 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/python_postman/exceptions/validation_error.py +0 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/python_postman/execution/auth_handler.py +0 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/python_postman/execution/context.py +0 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/python_postman/execution/exceptions.py +0 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/python_postman/execution/extensions.py +0 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/python_postman/execution/response.py +0 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/python_postman/execution/variable_resolver.py +0 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/python_postman/models/body.py +0 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/python_postman/models/collection_info.py +0 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/python_postman/models/event.py +0 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/python_postman/models/header.py +0 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/python_postman/models/variable.py +0 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/python_postman/parser.py +0 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/python_postman/utils/__init__.py +0 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/python_postman/utils/json_parser.py +0 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/python_postman/utils/validators.py +0 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/tests/__init__.py +0 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/tests/test_auth_handler.py +0 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/tests/test_body.py +0 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/tests/test_collection.py +0 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/tests/test_collection_info.py +0 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/tests/test_data/README.md +0 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/tests/test_data/README_integration_tests.md +0 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/tests/test_data/auth_collection.json +0 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/tests/test_data/auth_execution_collection.json +0 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/tests/test_data/cftc.gov.postman_collection.json +0 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/tests/test_data/empty_collection.json +0 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/tests/test_data/error_scenarios_collection.json +0 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/tests/test_data/events_collection.json +0 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/tests/test_data/execution_collection.json +0 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/tests/test_data/invalid_collection.json +0 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/tests/test_data/malformed_json.json +0 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/tests/test_data/nested_collection.json +0 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/tests/test_data/nested_execution_collection.json +0 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/tests/test_data/performance_collection.json +0 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/tests/test_data/simple_collection.json +0 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/tests/test_event.py +0 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/tests/test_exceptions.py +0 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/tests/test_execution_context.py +0 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/tests/test_execution_exceptions.py +0 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/tests/test_extensions.py +0 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/tests/test_folder.py +0 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/tests/test_header.py +0 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/tests/test_item.py +0 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/tests/test_json_parser.py +0 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/tests/test_request.py +0 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/tests/test_request_execution.py +0 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/tests/test_variable.py +0 -0
- {python_postman-0.8.0 → python_postman-0.9.0}/tests/test_variable_resolver.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: python-postman
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.9.0
|
|
4
4
|
Summary: A Python library for parsing and working with Postman collection.json files
|
|
5
5
|
Project-URL: Homepage, https://github.com/python-postman/python-postman
|
|
6
6
|
Project-URL: Repository, https://github.com/python-postman/python-postman
|
|
@@ -25,6 +25,7 @@ Classifier: Topic :: Internet :: WWW/HTTP
|
|
|
25
25
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
26
26
|
Classifier: Topic :: Software Development :: Testing
|
|
27
27
|
Requires-Python: >=3.9
|
|
28
|
+
Requires-Dist: httpx>=0.28.1
|
|
28
29
|
Provides-Extra: dev
|
|
29
30
|
Requires-Dist: black>=23.0.0; extra == 'dev'
|
|
30
31
|
Requires-Dist: isort>=5.12.0; extra == 'dev'
|
|
@@ -33,22 +34,21 @@ Requires-Dist: pytest-asyncio>=0.21.0; extra == 'dev'
|
|
|
33
34
|
Requires-Dist: pytest-cov>=4.0.0; extra == 'dev'
|
|
34
35
|
Requires-Dist: pytest>=8.4.2; extra == 'dev'
|
|
35
36
|
Provides-Extra: execution
|
|
36
|
-
Requires-Dist:
|
|
37
|
+
Requires-Dist: python-dotenv>=1.0.0; extra == 'execution'
|
|
37
38
|
Description-Content-Type: text/markdown
|
|
38
39
|
|
|
39
|
-
# Python Postman
|
|
40
|
+
# Python Postman
|
|
40
41
|
|
|
41
|
-
A Python library for
|
|
42
|
+
A comprehensive Python library for working with Postman collections. Parse, execute, search, and analyze Postman collection.json files with a clean, object-oriented interface. Execute HTTP requests with full async/sync support, dynamic variable resolution, and authentication handling.
|
|
42
43
|
|
|
43
44
|
## Features
|
|
44
45
|
|
|
45
46
|
- **Parse Postman Collections**: Load collections from files, JSON strings, or dictionaries
|
|
46
47
|
- **Object-Oriented API**: Work with collections using intuitive Python objects
|
|
47
|
-
- **Full Collection Support**: Access requests, folders, variables, authentication, and
|
|
48
|
+
- **Full Collection Support**: Access requests, folders, variables, authentication, and events
|
|
48
49
|
- **HTTP Request Execution**: Execute requests using httpx with full async/sync support
|
|
49
50
|
- **Variable Resolution**: Dynamic variable substitution with proper scoping
|
|
50
51
|
- **Authentication Handling**: Automatic auth processing for Bearer, Basic, and API Key
|
|
51
|
-
- **Script Execution**: Run pre-request and test scripts with result collection
|
|
52
52
|
- **Request Extensions**: Runtime modification of URLs, headers, body, and auth
|
|
53
53
|
- **Validation**: Built-in validation for collection structure and schema compliance
|
|
54
54
|
- **Iteration**: Easy iteration through all requests regardless of folder structure
|
|
@@ -95,9 +95,13 @@ print(f"Description: {collection.info.description}")
|
|
|
95
95
|
print(f"Schema: {collection.info.schema}")
|
|
96
96
|
|
|
97
97
|
# Collection-level variables
|
|
98
|
-
for variable in collection.variables:
|
|
98
|
+
for variable in collection.variables: # This requests a list of Variable objects
|
|
99
99
|
print(f"Variable: {variable.key} = {variable.value}")
|
|
100
100
|
|
|
101
|
+
# Collection variables dictionary. This is a quick way to get key-value pairs.
|
|
102
|
+
# You can pass/update these and add them to the execution context.
|
|
103
|
+
collection_variables = collection.get_variables()
|
|
104
|
+
|
|
101
105
|
# Collection-level authentication
|
|
102
106
|
if collection.auth:
|
|
103
107
|
print(f"Auth Type: {collection.auth.type}")
|
|
@@ -106,8 +110,16 @@ if collection.auth:
|
|
|
106
110
|
### Working with Requests
|
|
107
111
|
|
|
108
112
|
```python
|
|
113
|
+
# Get a list of requests by name
|
|
114
|
+
collection.list_requests()
|
|
115
|
+
|
|
116
|
+
# Find specific request by name
|
|
117
|
+
login_request = collection.get_request_by_name("Login Request")
|
|
118
|
+
if login_request:
|
|
119
|
+
print(f"Found request: {login_request.method} {login_request.url}")
|
|
120
|
+
|
|
109
121
|
# Iterate through all requests (flattens folder structure)
|
|
110
|
-
for request in collection.
|
|
122
|
+
for request in collection.get_requests():
|
|
111
123
|
print(f"Request: {request.method} {request.name}")
|
|
112
124
|
print(f"URL: {request.url}")
|
|
113
125
|
|
|
@@ -119,11 +131,6 @@ for request in collection.get_all_requests():
|
|
|
119
131
|
if request.body:
|
|
120
132
|
print(f"Body Type: {request.body.mode}")
|
|
121
133
|
print(f"Body Content: {request.body.raw}")
|
|
122
|
-
|
|
123
|
-
# Find specific request by name
|
|
124
|
-
request = collection.get_request_by_name("Login Request")
|
|
125
|
-
if request:
|
|
126
|
-
print(f"Found request: {request.method} {request.url}")
|
|
127
134
|
```
|
|
128
135
|
|
|
129
136
|
### Working with Folders
|
|
@@ -181,7 +188,7 @@ if collection.auth:
|
|
|
181
188
|
print(f"Basic Auth Username: {username}")
|
|
182
189
|
|
|
183
190
|
# Request-level auth (overrides collection auth)
|
|
184
|
-
for request in collection.
|
|
191
|
+
for request in collection.get_requests():
|
|
185
192
|
if request.auth:
|
|
186
193
|
print(f"Request '{request.name}' has {request.auth.type} auth")
|
|
187
194
|
```
|
|
@@ -189,18 +196,19 @@ for request in collection.get_all_requests():
|
|
|
189
196
|
### Events (Scripts)
|
|
190
197
|
|
|
191
198
|
```python
|
|
192
|
-
#
|
|
199
|
+
# Access script content from collection-level events
|
|
193
200
|
for event in collection.events:
|
|
194
201
|
print(f"Collection Event: {event.listen}")
|
|
195
|
-
print(f"Script: {event.script}")
|
|
202
|
+
print(f"Script Content: {event.script}")
|
|
196
203
|
|
|
197
|
-
#
|
|
198
|
-
|
|
204
|
+
# Access script content from request-level events
|
|
205
|
+
# Note: JavaScript execution is not supported - scripts are accessible as text only
|
|
206
|
+
for request in collection.get_requests():
|
|
199
207
|
for event in request.events:
|
|
200
208
|
if event.listen == "prerequest":
|
|
201
|
-
print(f"Pre-request script for {request.name}")
|
|
209
|
+
print(f"Pre-request script for {request.name}: {event.script}")
|
|
202
210
|
elif event.listen == "test":
|
|
203
|
-
print(f"Test script for {request.name}")
|
|
211
|
+
print(f"Test script for {request.name}: {event.script}")
|
|
204
212
|
```
|
|
205
213
|
|
|
206
214
|
### Validation
|
|
@@ -312,6 +320,12 @@ async def execute_collection():
|
|
|
312
320
|
parallel=True,
|
|
313
321
|
stop_on_error=False
|
|
314
322
|
)
|
|
323
|
+
|
|
324
|
+
# Get the request responses
|
|
325
|
+
for result in result.results:
|
|
326
|
+
print(f"Request: {result.request.name}")
|
|
327
|
+
print(f"Result Text: {result.response.text}")
|
|
328
|
+
|
|
315
329
|
print(f"Parallel execution completed in {result.total_time_ms:.2f}ms")
|
|
316
330
|
|
|
317
331
|
await executor.aclose()
|
|
@@ -458,21 +472,6 @@ except RequestExecutionError as e:
|
|
|
458
472
|
print(f"Execution error: {e}")
|
|
459
473
|
```
|
|
460
474
|
|
|
461
|
-
### Test Scripts and Results
|
|
462
|
-
|
|
463
|
-
```python
|
|
464
|
-
# Test results are automatically collected from test scripts
|
|
465
|
-
result = await executor.execute_request(request, context)
|
|
466
|
-
|
|
467
|
-
if result.test_results:
|
|
468
|
-
print(f"Tests: {result.test_results.passed} passed, {result.test_results.failed} failed")
|
|
469
|
-
|
|
470
|
-
# Check individual assertions
|
|
471
|
-
for assertion in result.test_results.assertions:
|
|
472
|
-
if not assertion.passed:
|
|
473
|
-
print(f"Failed: {assertion.name} - {assertion.error}")
|
|
474
|
-
```
|
|
475
|
-
|
|
476
475
|
## API Reference
|
|
477
476
|
|
|
478
477
|
### Main Classes
|
|
@@ -483,7 +482,7 @@ if result.test_results:
|
|
|
483
482
|
- **`Folder`**: Container for organizing requests and sub-folders
|
|
484
483
|
- **`Variable`**: Collection, folder, or request-level variables
|
|
485
484
|
- **`Auth`**: Authentication configuration
|
|
486
|
-
- **`Event`**: Pre-request
|
|
485
|
+
- **`Event`**: Pre-request and test script definitions (text only, execution not supported)
|
|
487
486
|
|
|
488
487
|
### Exception Handling
|
|
489
488
|
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
# Python Postman
|
|
1
|
+
# Python Postman
|
|
2
2
|
|
|
3
|
-
A Python library for
|
|
3
|
+
A comprehensive Python library for working with Postman collections. Parse, execute, search, and analyze Postman collection.json files with a clean, object-oriented interface. Execute HTTP requests with full async/sync support, dynamic variable resolution, and authentication handling.
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
7
|
- **Parse Postman Collections**: Load collections from files, JSON strings, or dictionaries
|
|
8
8
|
- **Object-Oriented API**: Work with collections using intuitive Python objects
|
|
9
|
-
- **Full Collection Support**: Access requests, folders, variables, authentication, and
|
|
9
|
+
- **Full Collection Support**: Access requests, folders, variables, authentication, and events
|
|
10
10
|
- **HTTP Request Execution**: Execute requests using httpx with full async/sync support
|
|
11
11
|
- **Variable Resolution**: Dynamic variable substitution with proper scoping
|
|
12
12
|
- **Authentication Handling**: Automatic auth processing for Bearer, Basic, and API Key
|
|
13
|
-
- **Script Execution**: Run pre-request and test scripts with result collection
|
|
14
13
|
- **Request Extensions**: Runtime modification of URLs, headers, body, and auth
|
|
15
14
|
- **Validation**: Built-in validation for collection structure and schema compliance
|
|
16
15
|
- **Iteration**: Easy iteration through all requests regardless of folder structure
|
|
@@ -57,9 +56,13 @@ print(f"Description: {collection.info.description}")
|
|
|
57
56
|
print(f"Schema: {collection.info.schema}")
|
|
58
57
|
|
|
59
58
|
# Collection-level variables
|
|
60
|
-
for variable in collection.variables:
|
|
59
|
+
for variable in collection.variables: # This requests a list of Variable objects
|
|
61
60
|
print(f"Variable: {variable.key} = {variable.value}")
|
|
62
61
|
|
|
62
|
+
# Collection variables dictionary. This is a quick way to get key-value pairs.
|
|
63
|
+
# You can pass/update these and add them to the execution context.
|
|
64
|
+
collection_variables = collection.get_variables()
|
|
65
|
+
|
|
63
66
|
# Collection-level authentication
|
|
64
67
|
if collection.auth:
|
|
65
68
|
print(f"Auth Type: {collection.auth.type}")
|
|
@@ -68,8 +71,16 @@ if collection.auth:
|
|
|
68
71
|
### Working with Requests
|
|
69
72
|
|
|
70
73
|
```python
|
|
74
|
+
# Get a list of requests by name
|
|
75
|
+
collection.list_requests()
|
|
76
|
+
|
|
77
|
+
# Find specific request by name
|
|
78
|
+
login_request = collection.get_request_by_name("Login Request")
|
|
79
|
+
if login_request:
|
|
80
|
+
print(f"Found request: {login_request.method} {login_request.url}")
|
|
81
|
+
|
|
71
82
|
# Iterate through all requests (flattens folder structure)
|
|
72
|
-
for request in collection.
|
|
83
|
+
for request in collection.get_requests():
|
|
73
84
|
print(f"Request: {request.method} {request.name}")
|
|
74
85
|
print(f"URL: {request.url}")
|
|
75
86
|
|
|
@@ -81,11 +92,6 @@ for request in collection.get_all_requests():
|
|
|
81
92
|
if request.body:
|
|
82
93
|
print(f"Body Type: {request.body.mode}")
|
|
83
94
|
print(f"Body Content: {request.body.raw}")
|
|
84
|
-
|
|
85
|
-
# Find specific request by name
|
|
86
|
-
request = collection.get_request_by_name("Login Request")
|
|
87
|
-
if request:
|
|
88
|
-
print(f"Found request: {request.method} {request.url}")
|
|
89
95
|
```
|
|
90
96
|
|
|
91
97
|
### Working with Folders
|
|
@@ -143,7 +149,7 @@ if collection.auth:
|
|
|
143
149
|
print(f"Basic Auth Username: {username}")
|
|
144
150
|
|
|
145
151
|
# Request-level auth (overrides collection auth)
|
|
146
|
-
for request in collection.
|
|
152
|
+
for request in collection.get_requests():
|
|
147
153
|
if request.auth:
|
|
148
154
|
print(f"Request '{request.name}' has {request.auth.type} auth")
|
|
149
155
|
```
|
|
@@ -151,18 +157,19 @@ for request in collection.get_all_requests():
|
|
|
151
157
|
### Events (Scripts)
|
|
152
158
|
|
|
153
159
|
```python
|
|
154
|
-
#
|
|
160
|
+
# Access script content from collection-level events
|
|
155
161
|
for event in collection.events:
|
|
156
162
|
print(f"Collection Event: {event.listen}")
|
|
157
|
-
print(f"Script: {event.script}")
|
|
163
|
+
print(f"Script Content: {event.script}")
|
|
158
164
|
|
|
159
|
-
#
|
|
160
|
-
|
|
165
|
+
# Access script content from request-level events
|
|
166
|
+
# Note: JavaScript execution is not supported - scripts are accessible as text only
|
|
167
|
+
for request in collection.get_requests():
|
|
161
168
|
for event in request.events:
|
|
162
169
|
if event.listen == "prerequest":
|
|
163
|
-
print(f"Pre-request script for {request.name}")
|
|
170
|
+
print(f"Pre-request script for {request.name}: {event.script}")
|
|
164
171
|
elif event.listen == "test":
|
|
165
|
-
print(f"Test script for {request.name}")
|
|
172
|
+
print(f"Test script for {request.name}: {event.script}")
|
|
166
173
|
```
|
|
167
174
|
|
|
168
175
|
### Validation
|
|
@@ -274,6 +281,12 @@ async def execute_collection():
|
|
|
274
281
|
parallel=True,
|
|
275
282
|
stop_on_error=False
|
|
276
283
|
)
|
|
284
|
+
|
|
285
|
+
# Get the request responses
|
|
286
|
+
for result in result.results:
|
|
287
|
+
print(f"Request: {result.request.name}")
|
|
288
|
+
print(f"Result Text: {result.response.text}")
|
|
289
|
+
|
|
277
290
|
print(f"Parallel execution completed in {result.total_time_ms:.2f}ms")
|
|
278
291
|
|
|
279
292
|
await executor.aclose()
|
|
@@ -420,21 +433,6 @@ except RequestExecutionError as e:
|
|
|
420
433
|
print(f"Execution error: {e}")
|
|
421
434
|
```
|
|
422
435
|
|
|
423
|
-
### Test Scripts and Results
|
|
424
|
-
|
|
425
|
-
```python
|
|
426
|
-
# Test results are automatically collected from test scripts
|
|
427
|
-
result = await executor.execute_request(request, context)
|
|
428
|
-
|
|
429
|
-
if result.test_results:
|
|
430
|
-
print(f"Tests: {result.test_results.passed} passed, {result.test_results.failed} failed")
|
|
431
|
-
|
|
432
|
-
# Check individual assertions
|
|
433
|
-
for assertion in result.test_results.assertions:
|
|
434
|
-
if not assertion.passed:
|
|
435
|
-
print(f"Failed: {assertion.name} - {assertion.error}")
|
|
436
|
-
```
|
|
437
|
-
|
|
438
436
|
## API Reference
|
|
439
437
|
|
|
440
438
|
### Main Classes
|
|
@@ -445,7 +443,7 @@ if result.test_results:
|
|
|
445
443
|
- **`Folder`**: Container for organizing requests and sub-folders
|
|
446
444
|
- **`Variable`**: Collection, folder, or request-level variables
|
|
447
445
|
- **`Auth`**: Authentication configuration
|
|
448
|
-
- **`Event`**: Pre-request
|
|
446
|
+
- **`Event`**: Pre-request and test script definitions (text only, execution not supported)
|
|
449
447
|
|
|
450
448
|
### Exception Handling
|
|
451
449
|
|