trafficmorph 0.3.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 (71) hide show
  1. trafficmorph-0.3.0/.gitignore +15 -0
  2. trafficmorph-0.3.0/LICENSE +201 -0
  3. trafficmorph-0.3.0/PKG-INFO +278 -0
  4. trafficmorph-0.3.0/README.md +249 -0
  5. trafficmorph-0.3.0/pyproject.toml +68 -0
  6. trafficmorph-0.3.0/trafficmorph/__init__.py +30 -0
  7. trafficmorph-0.3.0/trafficmorph/api/__init__.py +1 -0
  8. trafficmorph-0.3.0/trafficmorph/api/captures/__init__.py +1 -0
  9. trafficmorph-0.3.0/trafficmorph/api/captures/analyse.py +132 -0
  10. trafficmorph-0.3.0/trafficmorph/api/captures/import_capture.py +158 -0
  11. trafficmorph-0.3.0/trafficmorph/api/domains/__init__.py +1 -0
  12. trafficmorph-0.3.0/trafficmorph/api/domains/add.py +131 -0
  13. trafficmorph-0.3.0/trafficmorph/api/domains/list_domains.py +107 -0
  14. trafficmorph-0.3.0/trafficmorph/api/domains/remove.py +124 -0
  15. trafficmorph-0.3.0/trafficmorph/api/domains/verify_dns.py +124 -0
  16. trafficmorph-0.3.0/trafficmorph/api/domains/verify_http.py +122 -0
  17. trafficmorph-0.3.0/trafficmorph/api/history/__init__.py +1 -0
  18. trafficmorph-0.3.0/trafficmorph/api/history/get_history_item.py +122 -0
  19. trafficmorph-0.3.0/trafficmorph/api/history/list_history.py +210 -0
  20. trafficmorph-0.3.0/trafficmorph/api/profiles/__init__.py +1 -0
  21. trafficmorph-0.3.0/trafficmorph/api/profiles/create_profile.py +143 -0
  22. trafficmorph-0.3.0/trafficmorph/api/profiles/delete_profile.py +124 -0
  23. trafficmorph-0.3.0/trafficmorph/api/profiles/get_profile.py +122 -0
  24. trafficmorph-0.3.0/trafficmorph/api/profiles/list_profiles.py +107 -0
  25. trafficmorph-0.3.0/trafficmorph/api/profiles/update_profile.py +162 -0
  26. trafficmorph-0.3.0/trafficmorph/api/runs/__init__.py +1 -0
  27. trafficmorph-0.3.0/trafficmorph/api/runs/pause.py +122 -0
  28. trafficmorph-0.3.0/trafficmorph/api/runs/resume.py +120 -0
  29. trafficmorph-0.3.0/trafficmorph/api/runs/start.py +120 -0
  30. trafficmorph-0.3.0/trafficmorph/api/runs/stop.py +122 -0
  31. trafficmorph-0.3.0/trafficmorph/api/variables_sets/__init__.py +1 -0
  32. trafficmorph-0.3.0/trafficmorph/api/variables_sets/change_mode.py +142 -0
  33. trafficmorph-0.3.0/trafficmorph/api/variables_sets/create.py +157 -0
  34. trafficmorph-0.3.0/trafficmorph/api/variables_sets/delete.py +132 -0
  35. trafficmorph-0.3.0/trafficmorph/api/variables_sets/get.py +120 -0
  36. trafficmorph-0.3.0/trafficmorph/api/variables_sets/list_variables_sets.py +109 -0
  37. trafficmorph-0.3.0/trafficmorph/api/variables_sets/rename.py +134 -0
  38. trafficmorph-0.3.0/trafficmorph/client.py +271 -0
  39. trafficmorph-0.3.0/trafficmorph/errors.py +14 -0
  40. trafficmorph-0.3.0/trafficmorph/models/__init__.py +63 -0
  41. trafficmorph-0.3.0/trafficmorph/models/add_domain_request.py +76 -0
  42. trafficmorph-0.3.0/trafficmorph/models/analyse_body.py +102 -0
  43. trafficmorph-0.3.0/trafficmorph/models/api_profile_request.py +257 -0
  44. trafficmorph-0.3.0/trafficmorph/models/api_profile_response.py +313 -0
  45. trafficmorph-0.3.0/trafficmorph/models/capture_analysis_response.py +122 -0
  46. trafficmorph-0.3.0/trafficmorph/models/capture_import_result.py +152 -0
  47. trafficmorph-0.3.0/trafficmorph/models/change_variables_set_mode_request.py +80 -0
  48. trafficmorph-0.3.0/trafficmorph/models/change_variables_set_mode_request_mode.py +9 -0
  49. trafficmorph-0.3.0/trafficmorph/models/create_variables_set_request.py +96 -0
  50. trafficmorph-0.3.0/trafficmorph/models/create_variables_set_request_mode.py +9 -0
  51. trafficmorph-0.3.0/trafficmorph/models/created_profile.py +87 -0
  52. trafficmorph-0.3.0/trafficmorph/models/curve_point.py +87 -0
  53. trafficmorph-0.3.0/trafficmorph/models/group.py +197 -0
  54. trafficmorph-0.3.0/trafficmorph/models/import_capture_body.py +101 -0
  55. trafficmorph-0.3.0/trafficmorph/models/rename_variables_set_request.py +76 -0
  56. trafficmorph-0.3.0/trafficmorph/models/schedule_block.py +125 -0
  57. trafficmorph-0.3.0/trafficmorph/models/scheduled_run_response.py +150 -0
  58. trafficmorph-0.3.0/trafficmorph/models/skipped_selection.py +96 -0
  59. trafficmorph-0.3.0/trafficmorph/models/slot_input.py +87 -0
  60. trafficmorph-0.3.0/trafficmorph/models/slot_response.py +127 -0
  61. trafficmorph-0.3.0/trafficmorph/models/stats.py +123 -0
  62. trafficmorph-0.3.0/trafficmorph/models/traffic_profile_point_request.py +84 -0
  63. trafficmorph-0.3.0/trafficmorph/models/traffic_profile_point_response.py +87 -0
  64. trafficmorph-0.3.0/trafficmorph/models/traffic_profile_summary_response.py +109 -0
  65. trafficmorph-0.3.0/trafficmorph/models/traffic_run_control_response.py +96 -0
  66. trafficmorph-0.3.0/trafficmorph/models/variable.py +129 -0
  67. trafficmorph-0.3.0/trafficmorph/models/variables_set_response.py +190 -0
  68. trafficmorph-0.3.0/trafficmorph/models/variables_set_response_mode.py +9 -0
  69. trafficmorph-0.3.0/trafficmorph/models/verified_domain_response.py +173 -0
  70. trafficmorph-0.3.0/trafficmorph/sdk.py +360 -0
  71. trafficmorph-0.3.0/trafficmorph/types.py +53 -0
@@ -0,0 +1,15 @@
1
+ # Python venvs (created by `make install` / `make regen-client`).
2
+ .venv/
3
+ .venv-tools/
4
+
5
+ # Build artifacts.
6
+ dist/
7
+ build/
8
+ *.egg-info/
9
+
10
+ # Bytecode + caches.
11
+ __pycache__/
12
+ *.pyc
13
+ .pytest_cache/
14
+
15
+ .DS_Store
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for describing the origin of the Work and
141
+ reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may accept and charge a
167
+ fee for accepting support, warranty, indemnity, or other liability
168
+ obligations and/or rights consistent with this License. However, in
169
+ accepting such obligations, You may act only on Your own behalf
170
+ and on Your sole responsibility, not on behalf of any other
171
+ Contributor, and only if You agree to indemnify, defend, and hold
172
+ each Contributor harmless for any liability incurred by, or claims
173
+ asserted against, such Contributor by reason of your accepting any
174
+ such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
200
+ implied. See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,278 @@
1
+ Metadata-Version: 2.4
2
+ Name: trafficmorph
3
+ Version: 0.3.0
4
+ Summary: TrafficMorph Python SDK — typed client for the /api/v1 API.
5
+ Project-URL: Homepage, https://github.com/trafficmorph-gif/tm-python
6
+ Project-URL: Documentation, https://github.com/trafficmorph-gif/tm-python#readme
7
+ Project-URL: Repository, https://github.com/trafficmorph-gif/tm-python
8
+ Project-URL: Issues, https://github.com/trafficmorph-gif/tm-python/issues
9
+ Author-email: TrafficMorph <support@trafficmorph.io>
10
+ License-Expression: Apache-2.0
11
+ License-File: LICENSE
12
+ Keywords: ci,load-testing,regression-testing,trafficmorph
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Typing :: Typed
21
+ Requires-Python: >=3.10
22
+ Requires-Dist: attrs>=22.2.0
23
+ Requires-Dist: httpx<1.0,>=0.25
24
+ Requires-Dist: python-dateutil>=2.8.0
25
+ Provides-Extra: dev
26
+ Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
27
+ Requires-Dist: pytest>=7; extra == 'dev'
28
+ Description-Content-Type: text/markdown
29
+
30
+ # trafficmorph — TrafficMorph Python SDK
31
+
32
+ ```
33
+ ████████╗██████╗ █████╗ ███████╗███████╗██╗ ██████╗
34
+ ╚══██╔══╝██╔══██╗██╔══██╗██╔════╝██╔════╝██║██╔════╝
35
+ ██║ ██████╔╝███████║█████╗ █████╗ ██║██║
36
+ ██║ ██╔══██╗██╔══██║██╔══╝ ██╔══╝ ██║██║
37
+ ██║ ██║ ██║██║ ██║██║ ██║ ██║╚██████╗
38
+ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═════╝
39
+ ███╗ ███╗ ██████╗ ██████╗ ██████╗ ██╗ ██╗
40
+ ████╗ ████║██╔═══██╗██╔══██╗██╔══██╗██║ ██║
41
+ ██╔████╔██║██║ ██║██████╔╝██████╔╝███████║
42
+ ██║╚██╔╝██║██║ ██║██╔══██╗██╔═══╝ ██╔══██║
43
+ ██║ ╚═╝ ██║╚██████╔╝██║ ██║██║ ██║ ██║
44
+ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝
45
+ ```
46
+
47
+ [![PyPI](https://img.shields.io/pypi/v/trafficmorph)](https://pypi.org/project/trafficmorph/)
48
+ [![Python versions](https://img.shields.io/pypi/pyversions/trafficmorph)](https://pypi.org/project/trafficmorph/)
49
+ [![License](https://img.shields.io/pypi/l/trafficmorph)](LICENSE)
50
+ [![Downloads](https://img.shields.io/pypi/dm/trafficmorph)](https://pypi.org/project/trafficmorph/)
51
+
52
+ Typed Python client for the TrafficMorph `/api/v1` API. Request
53
+ and response shapes are typed `attrs` classes; endpoint methods
54
+ expose both sync and async call styles.
55
+
56
+ ## Install
57
+
58
+ ```bash
59
+ # Quick start — always picks up the latest release.
60
+ pip install trafficmorph
61
+
62
+ # Reproducible builds (CI / production) — pin to an exact version.
63
+ pip install 'trafficmorph==0.3.0'
64
+ ```
65
+
66
+ ## Prerequisites
67
+
68
+ - **Python 3.10 or newer** — declared minimum in [`pyproject.toml`](pyproject.toml). Required for PEP 604 union syntax (`str | None`).
69
+ - **A TrafficMorph API key** in the form `tm_…`. Provision one from the in-app **Settings → API keys** page.
70
+ - **A reachable TrafficMorph install.** The examples below assume `http://localhost:8080` for local development; swap for your hosted URL otherwise. There is no built-in default — the SDK requires the base URL to be set explicitly.
71
+
72
+ ## Quickstart
73
+
74
+ Export the two required values before running the program, so the snippet works as a single copy-paste:
75
+
76
+ ```bash
77
+ export TM_API_KEY="tm_your_key_here"
78
+ export TM_BASE_URL="http://localhost:8080" # or your hosted TrafficMorph URL
79
+ ```
80
+
81
+ Then:
82
+
83
+ ```python
84
+ import json
85
+ import os
86
+
87
+ from trafficmorph import Client
88
+ from trafficmorph.api.profiles import list_profiles
89
+
90
+ c = Client(
91
+ api_key=os.environ["TM_API_KEY"],
92
+ base_url=os.environ["TM_BASE_URL"],
93
+ timeout=15.0,
94
+ )
95
+
96
+ resp = list_profiles.sync_detailed(client=c.api)
97
+ print(f"status: {resp.status_code}, {len(resp.content)} bytes")
98
+ ```
99
+
100
+ ### First successful call checklist
101
+
102
+ - [ ] `tm_…` API key exported as `TM_API_KEY` (or passed as the `api_key=` kwarg).
103
+ - [ ] `TM_BASE_URL` points at a reachable TrafficMorph server (`http://localhost:8080` for local dev).
104
+ - [ ] Program prints `status: 200, N bytes` — an empty profile list is `[]`, so N is typically ≥ 2.
105
+ - [ ] `resp.content` holds the JSON payload (bytes). Decode it per [Decoding responses](#decoding-responses) below.
106
+
107
+ If the program errored before reaching the first line, jump to [Common errors](#common-errors).
108
+
109
+ ## Decoding responses
110
+
111
+ `resp.content` is the raw HTTP response body as `bytes`. Decode with `json` and the typed classes from `trafficmorph.models` — replace the `print(...)` line in the Quickstart with:
112
+
113
+ ```python
114
+ from trafficmorph.models import TrafficProfileSummaryResponse
115
+
116
+ if resp.status_code == 200:
117
+ profiles = [
118
+ TrafficProfileSummaryResponse.from_dict(p)
119
+ for p in json.loads(resp.content)
120
+ ]
121
+ for p in profiles:
122
+ print(p.id, p.name)
123
+ elif resp.status_code in (400, 401, 403, 404):
124
+ err = json.loads(resp.content)
125
+ raise SystemExit(f"server returned {resp.status_code}: {err.get('error')}")
126
+ else:
127
+ raise SystemExit(f"unexpected status {resp.status_code}: {resp.content!r}")
128
+ ```
129
+
130
+ The `*.from_dict` classmethod on every model handles the OpenAPI optional-field semantics — missing fields become `attrs.NOTHING` so you don't get surprise `KeyError`s.
131
+
132
+ For status-code branching alone (without decoding), use `resp.status_code`. `resp.content` is the raw bytes; `resp.headers` is the response headers.
133
+
134
+ ## Next steps
135
+
136
+ Three common flows after `list_profiles`:
137
+
138
+ ### Create a profile
139
+
140
+ ```python
141
+ from trafficmorph.api.profiles import create_profile
142
+ from trafficmorph.models import ApiProfileRequest, TrafficProfilePointRequest
143
+
144
+ body = ApiProfileRequest(
145
+ name="smoke-test",
146
+ target_url="https://api.example.com/health",
147
+ http_method="GET",
148
+ duration=60,
149
+ points=[
150
+ TrafficProfilePointRequest(x=0, y=10),
151
+ TrafficProfilePointRequest(x=60, y=10),
152
+ ],
153
+ )
154
+ resp = create_profile.sync_detailed(client=c.api, body=body)
155
+ ```
156
+
157
+ ### Start a run
158
+
159
+ ```python
160
+ from trafficmorph.api.runs import start
161
+
162
+ # profile_id from list_profiles or create_profile
163
+ resp = start.sync_detailed(client=c.api, id=profile_id)
164
+ # resp.status_code == 200 → run started; poll get_profile for status.
165
+ ```
166
+
167
+ ### View recent history
168
+
169
+ ```python
170
+ from trafficmorph.api.history import list_history
171
+
172
+ resp = list_history.sync_detailed(
173
+ client=c.api,
174
+ size=20,
175
+ # Other optional filters: profile_id, triggered_by, region, auto_verdict, tag.
176
+ )
177
+ ```
178
+
179
+ Every endpoint function exposes four call styles:
180
+
181
+ | Form | Returns |
182
+ |---|---|
183
+ | `endpoint.sync(client=…)` | Parsed body (currently `None` — see [Decoding responses](#decoding-responses)) |
184
+ | `endpoint.sync_detailed(client=…)` | `Response` with `.status_code`, `.content`, `.headers` |
185
+ | `endpoint.asyncio(client=…)` | Awaitable form of `sync` |
186
+ | `endpoint.asyncio_detailed(client=…)` | Awaitable form of `sync_detailed` |
187
+
188
+ For most cases, prefer `sync_detailed` / `asyncio_detailed` — they give you status code branching and the raw bytes for decoding.
189
+
190
+ ## Common errors
191
+
192
+ All errors below come from `Client(...)` — they surface at construction time, before any network call, so you don't need to set up the rest of your app to hit them.
193
+
194
+ | Error fragment | Cause | Fix |
195
+ |---|---|---|
196
+ | `api_key must not be empty` | First arg to `Client` is `""` — usually a missing `TM_API_KEY` env var. | Pass the literal key or `export TM_API_KEY=...` before running. |
197
+ | `api_key: value contains a carriage return …` (or newline, NUL, DEL, other control byte) | API key has stray whitespace / control chars (a common copy-paste artifact). | Only the literal `tm_…` characters belong in the value; strip surrounding whitespace. |
198
+ | `base_url is required: pass base_url='http://…'` | No `base_url=` kwarg AND no `$TM_BASE_URL` env var. | Pass `base_url="http://..."` or export `TM_BASE_URL`. |
199
+ | `base URL "…" must include http:// or https:// scheme` | Base URL is missing the protocol (e.g. `localhost:8080`). | Add the scheme: `http://localhost:8080`. |
200
+ | `base URL "…" has scheme "…"; must be http or https` | Non-`http`/`https` scheme (e.g. `ftp://…`). | Use `http://` or `https://`. |
201
+ | `base URL "…" must not contain a query string` | Base URL has `?key=value` appended. | Strip the query — attach per-request params at the endpoint call site instead. |
202
+ | `base URL "…" must not contain a fragment` | Base URL has `#foo` appended. | Strip the fragment — fragments are client-side only and meaningless to the server. |
203
+ | `$TM_BASE_URL: …` (any of the above) | Env-supplied base URL fails the same checks. | Same fixes; the prefix names the source so you know whether the kwarg or the env var was at fault. |
204
+
205
+ ## Configuration
206
+
207
+ | Source | Precedence |
208
+ |--------|------------|
209
+ | Constructor kwargs (`base_url=`, `timeout=`, …) | Highest |
210
+ | Environment variables (`TM_BASE_URL`) | Middle |
211
+ | Built-in defaults | Lowest |
212
+
213
+ | Kwarg | Env var | Default | Notes |
214
+ |---|---|---|---|
215
+ | `api_key` | — | _(required)_ | Full `tm_…` value. Empty string and header-invalid characters rejected upfront. |
216
+ | `base_url` | `TM_BASE_URL` | none — required | Points at your TrafficMorph install. See [Base URL rules](#base-url-rules) for accepted/rejected shapes. |
217
+ | `timeout` | — | `30.0` | Per-call timeout in seconds. Applied via `httpx.Timeout` on every request. |
218
+ | `user_agent` | — | `tm-python-sdk/<spec-version>` | Override to tag app traffic in HTTP logs (e.g. `"my-app/1.2.3 (tm-python-sdk/v1)"`). |
219
+ | `httpx_args` | — | `{}` | Extra kwargs forwarded to the underlying `httpx.Client` (proxies, mTLS, custom transports). |
220
+
221
+ ### Base URL rules
222
+
223
+ Kwarg and env values are validated and normalized the same way, so they produce identical results for the same logical input. The kwarg wins on conflict.
224
+
225
+ **Accepted shapes** — any absolute `http://` or `https://` URL with a non-empty host:
226
+
227
+ - `http://localhost:8080` — typical local dev.
228
+ - `https://app.example.com` — hosted deployment.
229
+ - `https://host/proxy-prefix` — reverse-proxy mount; the prefix is preserved during URL resolution.
230
+ - `https://host/a%2Fb` — percent-encoded path segments stay verbatim. Per RFC 3986, `/a%2Fb` (one segment, containing a literal slash) and `/a/b` (two segments) are semantically different paths — the SDK never collapses one into the other.
231
+
232
+ The SDK appends a trailing slash if missing, so both spellings (with or without) produce the same final value.
233
+
234
+ **Rejected at construction time** — clear error from `Client(...)`, not a late transport failure:
235
+
236
+ | Bad input | Error fragment |
237
+ |---|---|
238
+ | `""` or whitespace-only | `must not be empty` |
239
+ | `localhost:8080` (no scheme) | `must include … scheme` |
240
+ | `ftp://x` (wrong scheme) | `must be http or https` |
241
+ | `https://` (no host) | `must include a host` |
242
+ | `https://x/?q=1` (query) | `must not contain a query string` |
243
+ | `https://x/#frag` (fragment) | `must not contain a fragment` |
244
+
245
+ Query strings and fragments are refused because they belong on per-request URLs, not the deployment root.
246
+
247
+ ## Authentication
248
+
249
+ The SDK sends every request with `X-Api-Key: tm_…`. The API also accepts `Authorization: Bearer tm_…`, but the SDK uses `X-Api-Key`.
250
+
251
+ ## What's in the box
252
+
253
+ ```
254
+ trafficmorph ← public package (Client, env names, constants)
255
+ trafficmorph.api.<tag> ← endpoint modules, one per OpenAPI tag
256
+ trafficmorph.models ← typed request/response attrs classes
257
+ trafficmorph.errors ← UnexpectedStatus exception
258
+ ```
259
+
260
+ Endpoint coverage matches the server's `/api/v1` endpoints 1:1:
261
+
262
+ | Module | Endpoints |
263
+ |---|---|
264
+ | `trafficmorph.api.profiles` | `list_profiles`, `create_profile`, `get_profile`, `update_profile`, `delete_profile` |
265
+ | `trafficmorph.api.runs` | `start`, `stop`, `pause`, `resume` |
266
+ | `trafficmorph.api.history` | `list_history`, `get_history_item` |
267
+ | `trafficmorph.api.domains` | `list_`, `add`, `verify_dns`, `verify_http`, `remove` |
268
+ | `trafficmorph.api.captures` | `analyse`, `import_capture` |
269
+ | `trafficmorph.api.variables_sets` | `list_variables_sets`, `create`, `get`, `rename`, `change_mode`, `delete` |
270
+
271
+ ## Versioning
272
+
273
+ | | Symbol | Meaning |
274
+ |---|---|---|
275
+ | SDK release | PyPI version (`pip install trafficmorph==X.Y.Z`) | Pin in your `requirements.txt` or `pyproject.toml` |
276
+ | API version | `trafficmorph.SPEC_VERSION` (currently `"v1"`) | The `/api/v1` revision this SDK targets |
277
+
278
+ Each SDK release targets one specific server `/api/v1` revision. The server preserves backwards compatibility within `/api/v1`, so SDK and server versions move independently — any released SDK version works against any TrafficMorph server still exposing `/api/v1`.