python-postman 0.6.0__tar.gz → 0.7.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.
Files changed (76) hide show
  1. python_postman-0.7.0/.github/workflows/python-publish.yml +65 -0
  2. python_postman-0.7.0/.gitignore +132 -0
  3. python_postman-0.7.0/PKG-INFO +331 -0
  4. python_postman-0.7.0/README.md +296 -0
  5. python_postman-0.7.0/pyproject.toml +97 -0
  6. python_postman-0.7.0/python_postman/__init__.py +85 -0
  7. python_postman-0.7.0/python_postman/exceptions/__init__.py +15 -0
  8. python_postman-0.7.0/python_postman/exceptions/base.py +28 -0
  9. python_postman-0.7.0/python_postman/exceptions/file_error.py +16 -0
  10. python_postman-0.7.0/python_postman/exceptions/parse_error.py +16 -0
  11. python_postman-0.7.0/python_postman/exceptions/validation_error.py +16 -0
  12. python_postman-0.7.0/python_postman/models/__init__.py +37 -0
  13. python_postman-0.7.0/python_postman/models/auth.py +360 -0
  14. python_postman-0.7.0/python_postman/models/body.py +605 -0
  15. python_postman-0.7.0/python_postman/models/collection.py +292 -0
  16. python_postman-0.7.0/python_postman/models/collection_info.py +95 -0
  17. python_postman-0.7.0/python_postman/models/event.py +219 -0
  18. python_postman-0.7.0/python_postman/models/folder.py +137 -0
  19. python_postman-0.7.0/python_postman/models/header.py +423 -0
  20. python_postman-0.7.0/python_postman/models/item.py +44 -0
  21. python_postman-0.7.0/python_postman/models/request.py +147 -0
  22. python_postman-0.7.0/python_postman/models/url.py +415 -0
  23. python_postman-0.7.0/python_postman/models/variable.py +234 -0
  24. python_postman-0.7.0/python_postman/parser.py +134 -0
  25. python_postman-0.7.0/python_postman/utils/__init__.py +8 -0
  26. python_postman-0.7.0/python_postman/utils/json_parser.py +139 -0
  27. python_postman-0.7.0/python_postman/utils/validators.py +36 -0
  28. python_postman-0.7.0/tests/__init__.py +1 -0
  29. python_postman-0.7.0/tests/test_auth.py +445 -0
  30. python_postman-0.7.0/tests/test_body.py +509 -0
  31. python_postman-0.7.0/tests/test_collection.py +119 -0
  32. python_postman-0.7.0/tests/test_collection_info.py +145 -0
  33. python_postman-0.7.0/tests/test_data/README.md +58 -0
  34. python_postman-0.7.0/tests/test_data/auth_collection.json +153 -0
  35. python_postman-0.7.0/tests/test_data/empty_collection.json +9 -0
  36. python_postman-0.7.0/tests/test_data/events_collection.json +91 -0
  37. python_postman-0.7.0/tests/test_data/invalid_collection.json +14 -0
  38. python_postman-0.7.0/tests/test_data/malformed_json.json +16 -0
  39. python_postman-0.7.0/tests/test_data/nested_collection.json +192 -0
  40. python_postman-0.7.0/tests/test_data/simple_collection.json +62 -0
  41. python_postman-0.7.0/tests/test_event.py +400 -0
  42. python_postman-0.7.0/tests/test_exceptions.py +185 -0
  43. python_postman-0.7.0/tests/test_folder.py +197 -0
  44. python_postman-0.7.0/tests/test_header.py +520 -0
  45. python_postman-0.7.0/tests/test_integration.py +495 -0
  46. python_postman-0.7.0/tests/test_item.py +72 -0
  47. python_postman-0.7.0/tests/test_json_parser.py +341 -0
  48. python_postman-0.7.0/tests/test_parser.py +399 -0
  49. python_postman-0.7.0/tests/test_request.py +114 -0
  50. python_postman-0.7.0/tests/test_url.py +362 -0
  51. python_postman-0.7.0/tests/test_variable.py +279 -0
  52. python_postman-0.7.0/uv.lock +450 -0
  53. python_postman-0.6.0/PKG-INFO +0 -52
  54. python_postman-0.6.0/README.md +0 -28
  55. python_postman-0.6.0/pyproject.toml +0 -59
  56. python_postman-0.6.0/src/python_postman/__init__.py +0 -0
  57. python_postman-0.6.0/src/python_postman/__main__.py +0 -17
  58. python_postman-0.6.0/src/python_postman/auth.py +0 -77
  59. python_postman-0.6.0/src/python_postman/body.py +0 -33
  60. python_postman-0.6.0/src/python_postman/collection.py +0 -36
  61. python_postman-0.6.0/src/python_postman/config.py +0 -110
  62. python_postman-0.6.0/src/python_postman/environment.py +0 -101
  63. python_postman-0.6.0/src/python_postman/event.py +0 -30
  64. python_postman-0.6.0/src/python_postman/header.py +0 -18
  65. python_postman-0.6.0/src/python_postman/item.py +0 -28
  66. python_postman-0.6.0/src/python_postman/modules/file.py +0 -203
  67. python_postman-0.6.0/src/python_postman/modules/http.py +0 -186
  68. python_postman-0.6.0/src/python_postman/modules/logger.py +0 -49
  69. python_postman-0.6.0/src/python_postman/postman.py +0 -143
  70. python_postman-0.6.0/src/python_postman/request.py +0 -17
  71. python_postman-0.6.0/src/python_postman/template.py +0 -5
  72. python_postman-0.6.0/src/python_postman/url.py +0 -94
  73. python_postman-0.6.0/src/python_postman/utils/cli.py +0 -62
  74. python_postman-0.6.0/src/python_postman/utils/load_dotenvc.py +0 -101
  75. python_postman-0.6.0/src/python_postman/variable.py +0 -62
  76. {python_postman-0.6.0 → python_postman-0.7.0}/LICENSE +0 -0
@@ -0,0 +1,65 @@
1
+ # This workflow will upload a Python Package to PyPI when a release is published
2
+ # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries
3
+
4
+ name: Publish Python Package to PyPI
5
+
6
+ on:
7
+ release:
8
+ types: [published]
9
+
10
+ permissions:
11
+ contents: read
12
+
13
+ jobs:
14
+ build:
15
+ name: Build distribution 📦
16
+ runs-on: ubuntu-latest
17
+ steps:
18
+ - name: Checkout repository
19
+ uses: actions/checkout@v5
20
+
21
+ - name: Set up Python
22
+ uses: actions/setup-python@v6
23
+ with:
24
+ python-version: "3.x"
25
+ cache: pip # Cache pip dependencies for faster runs
26
+
27
+ - name: Install build dependencies
28
+ run: |
29
+ python -m pip install --upgrade pip
30
+ python -m pip install build
31
+
32
+ - name: Build package
33
+ run: python -m build
34
+
35
+ - name: Verify build artifacts
36
+ run: |
37
+ ls -la dist/
38
+ python -m pip install twine
39
+ python -m twine check dist/*
40
+
41
+ - name: Store the distribution packages
42
+ uses: actions/upload-artifact@v4
43
+ with:
44
+ name: python-package-distributions
45
+ path: dist/
46
+
47
+ publish-to-pypi:
48
+ name: Publish Python 🐍 distribution 📦 to PyPI
49
+ needs: [build]
50
+ runs-on: ubuntu-latest
51
+ environment:
52
+ name: pypi
53
+ url: https://pypi.org/p/${{ github.event.repository.name }}
54
+ permissions:
55
+ id-token: write # IMPORTANT: mandatory for trusted publishing
56
+
57
+ steps:
58
+ - name: Download all the dists
59
+ uses: actions/download-artifact@v4
60
+ with:
61
+ name: python-package-distributions
62
+ path: dist/
63
+
64
+ - name: Publish distribution 📦 to PyPI
65
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,132 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ pip-wheel-metadata/
24
+ share/python-wheels/
25
+ *.egg-info/
26
+ .installed.cfg
27
+ *.egg
28
+ MANIFEST
29
+
30
+ # PyInstaller
31
+ # Usually these files are written by a python script from a template
32
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
33
+ *.manifest
34
+ *.spec
35
+
36
+ # Installer logs
37
+ pip-log.txt
38
+ pip-delete-this-directory.txt
39
+
40
+ # Unit test / coverage reports
41
+ htmlcov/
42
+ .tox/
43
+ .nox/
44
+ .coverage
45
+ .coverage.*
46
+ .cache
47
+ nosetests.xml
48
+ coverage.xml
49
+ *.cover
50
+ *.py,cover
51
+ .hypothesis/
52
+ .pytest_cache/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ target/
76
+
77
+ # Jupyter Notebook
78
+ .ipynb_checkpoints
79
+
80
+ # IPython
81
+ profile_default/
82
+ ipython_config.py
83
+
84
+ # pyenv
85
+ .python-version
86
+
87
+ # pipenv
88
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
89
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
90
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
91
+ # install all needed dependencies.
92
+ #Pipfile.lock
93
+
94
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow
95
+ __pypackages__/
96
+
97
+ # Celery stuff
98
+ celerybeat-schedule
99
+ celerybeat.pid
100
+
101
+ # SageMath parsed files
102
+ *.sage.py
103
+
104
+ # Environments
105
+ .env
106
+ .venv
107
+ env/
108
+ venv/
109
+ ENV/
110
+ env.bak/
111
+ venv.bak/
112
+
113
+ # Spyder project settings
114
+ .spyderproject
115
+ .spyproject
116
+
117
+ # Rope project settings
118
+ .ropeproject
119
+
120
+ # mkdocs documentation
121
+ /site
122
+
123
+ # mypy
124
+ .mypy_cache/
125
+ .dmypy.json
126
+ dmypy.json
127
+
128
+ # Pyre type checker
129
+ .pyre/
130
+
131
+ .DS_Store
132
+ .kiro
@@ -0,0 +1,331 @@
1
+ Metadata-Version: 2.4
2
+ Name: python-postman
3
+ Version: 0.7.0
4
+ Summary: A Python library for parsing and working with Postman collection.json files
5
+ Project-URL: Homepage, https://github.com/python-postman/python-postman
6
+ Project-URL: Repository, https://github.com/python-postman/python-postman
7
+ Project-URL: Documentation, https://python-postman.readthedocs.io
8
+ Project-URL: Bug Tracker, https://github.com/python-postman/python-postman/issues
9
+ Author: Python Postman Contributors
10
+ License: MIT
11
+ License-File: LICENSE
12
+ Keywords: api,collection,http,parser,postman,testing
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.8
19
+ Classifier: Programming Language :: Python :: 3.9
20
+ Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
23
+ Classifier: Programming Language :: Python :: 3.13
24
+ Classifier: Topic :: Internet :: WWW/HTTP
25
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
26
+ Classifier: Topic :: Software Development :: Testing
27
+ Requires-Python: >=3.9
28
+ Provides-Extra: dev
29
+ Requires-Dist: black>=23.0.0; extra == 'dev'
30
+ Requires-Dist: isort>=5.12.0; extra == 'dev'
31
+ Requires-Dist: mypy>=1.0.0; extra == 'dev'
32
+ Requires-Dist: pytest-cov>=4.0.0; extra == 'dev'
33
+ Requires-Dist: pytest>=8.4.2; extra == 'dev'
34
+ Description-Content-Type: text/markdown
35
+
36
+ # Python Postman Collection Parser
37
+
38
+ A Python library for parsing and working with Postman collection.json files. This library provides a clean, object-oriented interface for reading Postman collections and accessing their components programmatically.
39
+
40
+ ## Features
41
+
42
+ - **Parse Postman Collections**: Load collections from files, JSON strings, or dictionaries
43
+ - **Object-Oriented API**: Work with collections using intuitive Python objects
44
+ - **Full Collection Support**: Access requests, folders, variables, authentication, and scripts
45
+ - **Validation**: Built-in validation for collection structure and schema compliance
46
+ - **Iteration**: Easy iteration through all requests regardless of folder structure
47
+ - **Search**: Find requests and folders by name
48
+ - **Type Hints**: Full type annotation support for better IDE experience
49
+
50
+ ## Installation
51
+
52
+ ```bash
53
+ pip install python-postman
54
+ ```
55
+
56
+ ## Quick Start
57
+
58
+ ### Loading a Collection
59
+
60
+ ```python
61
+ from python_postman import PythonPostman
62
+
63
+ # Load from file
64
+ collection = PythonPostman.from_file("path/to/collection.json")
65
+
66
+ # Load from JSON string
67
+ json_string = '{"info": {"name": "My Collection"}, "item": []}'
68
+ collection = PythonPostman.from_json(json_string)
69
+
70
+ # Load from dictionary
71
+ collection_dict = {"info": {"name": "My Collection"}, "item": []}
72
+ collection = PythonPostman.from_dict(collection_dict)
73
+ ```
74
+
75
+ ### Accessing Collection Information
76
+
77
+ ```python
78
+ # Basic collection info
79
+ print(f"Collection Name: {collection.info.name}")
80
+ print(f"Description: {collection.info.description}")
81
+ print(f"Schema: {collection.info.schema}")
82
+
83
+ # Collection-level variables
84
+ for variable in collection.variables:
85
+ print(f"Variable: {variable.key} = {variable.value}")
86
+
87
+ # Collection-level authentication
88
+ if collection.auth:
89
+ print(f"Auth Type: {collection.auth.type}")
90
+ ```
91
+
92
+ ### Working with Requests
93
+
94
+ ```python
95
+ # Iterate through all requests (flattens folder structure)
96
+ for request in collection.get_all_requests():
97
+ print(f"Request: {request.method} {request.name}")
98
+ print(f"URL: {request.url}")
99
+
100
+ # Access headers
101
+ for header in request.headers:
102
+ print(f"Header: {header.key} = {header.value}")
103
+
104
+ # Access request body
105
+ if request.body:
106
+ print(f"Body Type: {request.body.mode}")
107
+ print(f"Body Content: {request.body.raw}")
108
+
109
+ # Find specific request by name
110
+ request = collection.get_request_by_name("Login Request")
111
+ if request:
112
+ print(f"Found request: {request.method} {request.url}")
113
+ ```
114
+
115
+ ### Working with Folders
116
+
117
+ ```python
118
+ # Access top-level items
119
+ for item in collection.items:
120
+ if hasattr(item, 'items'): # It's a folder
121
+ print(f"Folder: {item.name}")
122
+ print(f"Items in folder: {len(item.items)}")
123
+
124
+ # Get all requests in this folder
125
+ for request in item.get_requests():
126
+ print(f" Request: {request.name}")
127
+ else: # It's a request
128
+ print(f"Request: {item.name}")
129
+
130
+ # Find specific folder by name
131
+ folder = collection.get_folder_by_name("Authentication")
132
+ if folder:
133
+ print(f"Found folder: {folder.name}")
134
+ print(f"Subfolders: {len(folder.get_subfolders())}")
135
+ ```
136
+
137
+ ### Working with Variables
138
+
139
+ ```python
140
+ # Collection variables
141
+ for var in collection.variables:
142
+ print(f"Collection Variable: {var.key} = {var.value}")
143
+ if var.description:
144
+ print(f" Description: {var.description}")
145
+
146
+ # Folder variables (if folder has variables)
147
+ for item in collection.items:
148
+ if hasattr(item, 'variables') and item.variables:
149
+ print(f"Folder '{item.name}' variables:")
150
+ for var in item.variables:
151
+ print(f" {var.key} = {var.value}")
152
+ ```
153
+
154
+ ### Authentication
155
+
156
+ ```python
157
+ # Collection-level auth
158
+ if collection.auth:
159
+ print(f"Collection Auth: {collection.auth.type}")
160
+
161
+ # Access auth details based on type
162
+ if collection.auth.type == "bearer":
163
+ token = collection.auth.bearer.get("token")
164
+ print(f"Bearer Token: {token}")
165
+ elif collection.auth.type == "basic":
166
+ username = collection.auth.basic.get("username")
167
+ print(f"Basic Auth Username: {username}")
168
+
169
+ # Request-level auth (overrides collection auth)
170
+ for request in collection.get_all_requests():
171
+ if request.auth:
172
+ print(f"Request '{request.name}' has {request.auth.type} auth")
173
+ ```
174
+
175
+ ### Events (Scripts)
176
+
177
+ ```python
178
+ # Collection-level events
179
+ for event in collection.events:
180
+ print(f"Collection Event: {event.listen}")
181
+ print(f"Script: {event.script}")
182
+
183
+ # Request-level events
184
+ for request in collection.get_all_requests():
185
+ for event in request.events:
186
+ if event.listen == "prerequest":
187
+ print(f"Pre-request script for {request.name}")
188
+ elif event.listen == "test":
189
+ print(f"Test script for {request.name}")
190
+ ```
191
+
192
+ ### Validation
193
+
194
+ ```python
195
+ # Validate collection structure
196
+ validation_result = collection.validate()
197
+
198
+ if validation_result.is_valid:
199
+ print("Collection is valid!")
200
+ else:
201
+ print("Collection validation failed:")
202
+ for error in validation_result.errors:
203
+ print(f" - {error}")
204
+
205
+ # Quick validation without creating full objects
206
+ is_valid = PythonPostman.validate_collection_dict(collection_dict)
207
+ print(f"Collection dict is valid: {is_valid}")
208
+ ```
209
+
210
+ ### Creating New Collections
211
+
212
+ ```python
213
+ # Create a new empty collection
214
+ collection = PythonPostman.create_collection(
215
+ name="My New Collection",
216
+ description="A collection created programmatically"
217
+ )
218
+
219
+ print(f"Created collection: {collection.info.name}")
220
+ ```
221
+
222
+ ## API Reference
223
+
224
+ ### Main Classes
225
+
226
+ - **`PythonPostman`**: Main entry point for loading collections
227
+ - **`Collection`**: Represents a complete Postman collection
228
+ - **`Request`**: Individual HTTP request
229
+ - **`Folder`**: Container for organizing requests and sub-folders
230
+ - **`Variable`**: Collection, folder, or request-level variables
231
+ - **`Auth`**: Authentication configuration
232
+ - **`Event`**: Pre-request scripts and test scripts
233
+
234
+ ### Exception Handling
235
+
236
+ The library provides specific exceptions for different error scenarios:
237
+
238
+ ```python
239
+ from python_postman import (
240
+ PostmanCollectionError, # Base exception
241
+ CollectionParseError, # JSON parsing errors
242
+ CollectionValidationError, # Structure validation errors
243
+ CollectionFileError, # File operation errors
244
+ )
245
+
246
+ try:
247
+ collection = PythonPostman.from_file("collection.json")
248
+ except CollectionFileError as e:
249
+ print(f"File error: {e}")
250
+ except CollectionParseError as e:
251
+ print(f"Parse error: {e}")
252
+ except CollectionValidationError as e:
253
+ print(f"Validation error: {e}")
254
+ ```
255
+
256
+ ## Requirements
257
+
258
+ - Python 3.8+
259
+ - No external dependencies for core functionality
260
+
261
+ ## Development
262
+
263
+ ### Setting up Development Environment
264
+
265
+ ```bash
266
+ # Clone the repository
267
+ git clone https://github.com/python-postman/python-postman.git
268
+ cd python-postman
269
+
270
+ # Install development dependencies
271
+ pip install -e ".[dev]"
272
+
273
+ # Run tests
274
+ pytest
275
+
276
+ # Run tests with coverage
277
+ pytest --cov=python_postman
278
+
279
+ # Format code
280
+ black python_postman tests
281
+ isort python_postman tests
282
+
283
+ # Type checking
284
+ mypy python_postman
285
+ ```
286
+
287
+ ### Running Tests
288
+
289
+ ```bash
290
+ # Run all tests
291
+ pytest
292
+
293
+ # Run specific test file
294
+ pytest tests/test_collection.py
295
+
296
+ # Run with verbose output
297
+ pytest -v
298
+
299
+ # Run with coverage report
300
+ pytest --cov=python_postman --cov-report=html
301
+ ```
302
+
303
+ ## Contributing
304
+
305
+ Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
306
+
307
+ 1. Fork the repository
308
+ 2. Create your feature branch (`git checkout -b feature/amazing-feature`)
309
+ 3. Commit your changes (`git commit -m 'Add some amazing feature'`)
310
+ 4. Push to the branch (`git push origin feature/amazing-feature`)
311
+ 5. Open a Pull Request
312
+
313
+ ## License
314
+
315
+ This project is licensed under the MIT License - see the LICENSE file for details.
316
+
317
+ ## Changelog
318
+
319
+ ### 0.7.0 (Updated version)
320
+
321
+ - Updated version to 0.7.0
322
+ - Updated README.md
323
+ - Updated pyproject.toml
324
+ - Updated tests
325
+ - Updated docs
326
+ - Updated examples
327
+ - Updated code
328
+
329
+ ## Support
330
+
331
+ If you encounter any issues or have questions, please file an issue on the [GitHub issue tracker](https://github.com/python-postman/python-postman/issues).