train-travel 0.0.7__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 (68) hide show
  1. train_travel-0.0.7/PKG-INFO +567 -0
  2. train_travel-0.0.7/README-PYPI.md +554 -0
  3. train_travel-0.0.7/README.md +554 -0
  4. train_travel-0.0.7/pyproject.toml +54 -0
  5. train_travel-0.0.7/setup.cfg +4 -0
  6. train_travel-0.0.7/src/train_travel/__init__.py +17 -0
  7. train_travel-0.0.7/src/train_travel/_hooks/__init__.py +6 -0
  8. train_travel-0.0.7/src/train_travel/_hooks/oauth2scopes.py +16 -0
  9. train_travel-0.0.7/src/train_travel/_hooks/registration.py +13 -0
  10. train_travel-0.0.7/src/train_travel/_hooks/sdkhooks.py +76 -0
  11. train_travel-0.0.7/src/train_travel/_hooks/types.py +112 -0
  12. train_travel-0.0.7/src/train_travel/_version.py +15 -0
  13. train_travel-0.0.7/src/train_travel/basesdk.py +388 -0
  14. train_travel-0.0.7/src/train_travel/bookings.py +1190 -0
  15. train_travel-0.0.7/src/train_travel/errors/__init__.py +63 -0
  16. train_travel-0.0.7/src/train_travel/errors/no_response_error.py +17 -0
  17. train_travel-0.0.7/src/train_travel/errors/responsevalidationerror.py +27 -0
  18. train_travel-0.0.7/src/train_travel/errors/traintraveldefaulterror.py +40 -0
  19. train_travel-0.0.7/src/train_travel/errors/traintravelerror.py +30 -0
  20. train_travel-0.0.7/src/train_travel/httpclient.py +125 -0
  21. train_travel-0.0.7/src/train_travel/models/__init__.py +416 -0
  22. train_travel-0.0.7/src/train_travel/models/booking.py +59 -0
  23. train_travel-0.0.7/src/train_travel/models/booking_input.py +52 -0
  24. train_travel-0.0.7/src/train_travel/models/bookingpayment.py +221 -0
  25. train_travel-0.0.7/src/train_travel/models/create_booking_paymentop.py +269 -0
  26. train_travel-0.0.7/src/train_travel/models/create_booking_rawop.py +144 -0
  27. train_travel-0.0.7/src/train_travel/models/create_bookingop.py +144 -0
  28. train_travel-0.0.7/src/train_travel/models/delete_bookingop.py +30 -0
  29. train_travel-0.0.7/src/train_travel/models/get_bookingop.py +159 -0
  30. train_travel-0.0.7/src/train_travel/models/get_bookingsop.py +198 -0
  31. train_travel-0.0.7/src/train_travel/models/get_stationsop.py +230 -0
  32. train_travel-0.0.7/src/train_travel/models/get_tripsop.py +324 -0
  33. train_travel-0.0.7/src/train_travel/models/links_booking.py +35 -0
  34. train_travel-0.0.7/src/train_travel/models/links_self.py +36 -0
  35. train_travel-0.0.7/src/train_travel/models/new_bookingop.py +92 -0
  36. train_travel-0.0.7/src/train_travel/models/security.py +39 -0
  37. train_travel-0.0.7/src/train_travel/models/station.py +57 -0
  38. train_travel-0.0.7/src/train_travel/models/trip.py +90 -0
  39. train_travel-0.0.7/src/train_travel/payments.py +262 -0
  40. train_travel-0.0.7/src/train_travel/py.typed +1 -0
  41. train_travel-0.0.7/src/train_travel/sdk.py +213 -0
  42. train_travel-0.0.7/src/train_travel/sdkconfiguration.py +51 -0
  43. train_travel-0.0.7/src/train_travel/stations.py +284 -0
  44. train_travel-0.0.7/src/train_travel/trips.py +291 -0
  45. train_travel-0.0.7/src/train_travel/types/__init__.py +21 -0
  46. train_travel-0.0.7/src/train_travel/types/basemodel.py +77 -0
  47. train_travel-0.0.7/src/train_travel/utils/__init__.py +206 -0
  48. train_travel-0.0.7/src/train_travel/utils/annotations.py +79 -0
  49. train_travel-0.0.7/src/train_travel/utils/datetimes.py +23 -0
  50. train_travel-0.0.7/src/train_travel/utils/enums.py +134 -0
  51. train_travel-0.0.7/src/train_travel/utils/eventstreaming.py +248 -0
  52. train_travel-0.0.7/src/train_travel/utils/forms.py +234 -0
  53. train_travel-0.0.7/src/train_travel/utils/headers.py +136 -0
  54. train_travel-0.0.7/src/train_travel/utils/logger.py +27 -0
  55. train_travel-0.0.7/src/train_travel/utils/metadata.py +118 -0
  56. train_travel-0.0.7/src/train_travel/utils/queryparams.py +217 -0
  57. train_travel-0.0.7/src/train_travel/utils/requestbodies.py +66 -0
  58. train_travel-0.0.7/src/train_travel/utils/retries.py +281 -0
  59. train_travel-0.0.7/src/train_travel/utils/security.py +192 -0
  60. train_travel-0.0.7/src/train_travel/utils/serializers.py +229 -0
  61. train_travel-0.0.7/src/train_travel/utils/unmarshal_json_response.py +38 -0
  62. train_travel-0.0.7/src/train_travel/utils/url.py +155 -0
  63. train_travel-0.0.7/src/train_travel/utils/values.py +137 -0
  64. train_travel-0.0.7/src/train_travel.egg-info/PKG-INFO +567 -0
  65. train_travel-0.0.7/src/train_travel.egg-info/SOURCES.txt +66 -0
  66. train_travel-0.0.7/src/train_travel.egg-info/dependency_links.txt +1 -0
  67. train_travel-0.0.7/src/train_travel.egg-info/requires.txt +3 -0
  68. train_travel-0.0.7/src/train_travel.egg-info/top_level.txt +1 -0
@@ -0,0 +1,567 @@
1
+ Metadata-Version: 2.4
2
+ Name: train-travel
3
+ Version: 0.0.7
4
+ Summary: Python Client SDK Generated by Speakeasy.
5
+ Author: Speakeasy
6
+ License: Apache-2.0
7
+ Project-URL: repository, https://github.com/danielkov/train-travel.git
8
+ Requires-Python: >=3.10
9
+ Description-Content-Type: text/markdown
10
+ Requires-Dist: httpcore>=1.0.9
11
+ Requires-Dist: httpx>=0.28.1
12
+ Requires-Dist: pydantic>=2.11.2
13
+
14
+ # train-travel
15
+
16
+ Developer-friendly & type-safe Python SDK specifically catered to leverage *train-travel* API.
17
+
18
+ [![Built by Speakeasy](https://img.shields.io/badge/Built_by-SPEAKEASY-374151?style=for-the-badge&labelColor=f3f4f6)](https://www.speakeasy.com/?utm_source=train-travel&utm_campaign=python)
19
+ [![License: MIT](https://img.shields.io/badge/LICENSE_//_MIT-3b5bdb?style=for-the-badge&labelColor=eff6ff)](https://opensource.org/licenses/MIT)
20
+
21
+
22
+ <br /><br />
23
+ > [!IMPORTANT]
24
+ > This SDK is not yet ready for production use. To complete setup please follow the steps outlined in your [workspace](https://app.speakeasy.com/org/speakeasy-self/daniel-test). Delete this section before > publishing to a package manager.
25
+
26
+ <!-- Start Summary [summary] -->
27
+ ## Summary
28
+
29
+ Train Travel API: API for finding and booking train trips across Europe.
30
+
31
+ ## Run in Postman
32
+
33
+ Experiment with this API in Postman, using our Postman Collection.
34
+
35
+ [![Run In Postman](https://run.pstmn.io/button.svg =128pxx32px)](https://app.getpostman.com/run-collection/9265903-7a75a0d0-b108-4436-ba54-c6139698dc08?action=collection%2Ffork&source=rip_markdown&collection-url=entityId%3D9265903-7a75a0d0-b108-4436-ba54-c6139698dc08%26entityType%3Dcollection%26workspaceId%3Df507f69d-9564-419c-89a2-cb8e4c8c7b8f)
36
+ <!-- End Summary [summary] -->
37
+
38
+ <!-- Start Table of Contents [toc] -->
39
+ ## Table of Contents
40
+ <!-- $toc-max-depth=2 -->
41
+ * [train-travel](https://github.com/danielkov/train-travel/blob/master/train-travel-python/#train-travel)
42
+ * [Run in Postman](https://github.com/danielkov/train-travel/blob/master/train-travel-python/#run-in-postman)
43
+ * [SDK Installation](https://github.com/danielkov/train-travel/blob/master/train-travel-python/#sdk-installation)
44
+ * [IDE Support](https://github.com/danielkov/train-travel/blob/master/train-travel-python/#ide-support)
45
+ * [SDK Example Usage](https://github.com/danielkov/train-travel/blob/master/train-travel-python/#sdk-example-usage)
46
+ * [Authentication](https://github.com/danielkov/train-travel/blob/master/train-travel-python/#authentication)
47
+ * [Available Resources and Operations](https://github.com/danielkov/train-travel/blob/master/train-travel-python/#available-resources-and-operations)
48
+ * [File uploads](https://github.com/danielkov/train-travel/blob/master/train-travel-python/#file-uploads)
49
+ * [Retries](https://github.com/danielkov/train-travel/blob/master/train-travel-python/#retries)
50
+ * [Error Handling](https://github.com/danielkov/train-travel/blob/master/train-travel-python/#error-handling)
51
+ * [Server Selection](https://github.com/danielkov/train-travel/blob/master/train-travel-python/#server-selection)
52
+ * [Custom HTTP Client](https://github.com/danielkov/train-travel/blob/master/train-travel-python/#custom-http-client)
53
+ * [Resource Management](https://github.com/danielkov/train-travel/blob/master/train-travel-python/#resource-management)
54
+ * [Debugging](https://github.com/danielkov/train-travel/blob/master/train-travel-python/#debugging)
55
+ * [Development](https://github.com/danielkov/train-travel/blob/master/train-travel-python/#development)
56
+ * [Maturity](https://github.com/danielkov/train-travel/blob/master/train-travel-python/#maturity)
57
+ * [Contributions](https://github.com/danielkov/train-travel/blob/master/train-travel-python/#contributions)
58
+
59
+ <!-- End Table of Contents [toc] -->
60
+
61
+ <!-- Start SDK Installation [installation] -->
62
+ ## SDK Installation
63
+
64
+ > [!NOTE]
65
+ > **Python version upgrade policy**
66
+ >
67
+ > Once a Python version reaches its [official end of life date](https://devguide.python.org/versions/), a 3-month grace period is provided for users to upgrade. Following this grace period, the minimum python version supported in the SDK will be updated.
68
+
69
+ The SDK can be installed with *uv*, *pip*, or *poetry* package managers.
70
+
71
+ ### uv
72
+
73
+ *uv* is a fast Python package installer and resolver, designed as a drop-in replacement for pip and pip-tools. It's recommended for its speed and modern Python tooling capabilities.
74
+
75
+ ```bash
76
+ uv add train-travel
77
+ ```
78
+
79
+ ### PIP
80
+
81
+ *PIP* is the default package installer for Python, enabling easy installation and management of packages from PyPI via the command line.
82
+
83
+ ```bash
84
+ pip install train-travel
85
+ ```
86
+
87
+ ### Poetry
88
+
89
+ *Poetry* is a modern tool that simplifies dependency management and package publishing by using a single `pyproject.toml` file to handle project metadata and dependencies.
90
+
91
+ ```bash
92
+ poetry add train-travel
93
+ ```
94
+
95
+ ### Shell and script usage with `uv`
96
+
97
+ You can use this SDK in a Python shell with [uv](https://docs.astral.sh/uv/) and the `uvx` command that comes with it like so:
98
+
99
+ ```shell
100
+ uvx --from train-travel python
101
+ ```
102
+
103
+ It's also possible to write a standalone Python script without needing to set up a whole project like so:
104
+
105
+ ```python
106
+ #!/usr/bin/env -S uv run --script
107
+ # /// script
108
+ # requires-python = ">=3.10"
109
+ # dependencies = [
110
+ # "train-travel",
111
+ # ]
112
+ # ///
113
+
114
+ from train_travel import TrainTravel
115
+
116
+ sdk = TrainTravel(
117
+ # SDK arguments
118
+ )
119
+
120
+ # Rest of script here...
121
+ ```
122
+
123
+ Once that is saved to a file, you can run it with `uv run script.py` where
124
+ `script.py` can be replaced with the actual file name.
125
+ <!-- End SDK Installation [installation] -->
126
+
127
+ <!-- Start IDE Support [idesupport] -->
128
+ ## IDE Support
129
+
130
+ ### PyCharm
131
+
132
+ Generally, the SDK will work well with most IDEs out of the box. However, when using PyCharm, you can enjoy much better integration with Pydantic by installing an additional plugin.
133
+
134
+ - [PyCharm Pydantic Plugin](https://docs.pydantic.dev/latest/integrations/pycharm/)
135
+ <!-- End IDE Support [idesupport] -->
136
+
137
+ <!-- Start SDK Example Usage [usage] -->
138
+ ## SDK Example Usage
139
+
140
+ ### Example
141
+
142
+ ```python
143
+ # Synchronous Example
144
+ import os
145
+ from train_travel import TrainTravel
146
+
147
+
148
+ with TrainTravel(
149
+ o_auth2=os.getenv("TRAINTRAVEL_O_AUTH2", ""),
150
+ ) as tt_client:
151
+
152
+ res = tt_client.stations.get_stations(page=1, limit=10, coordinates="52.5200,13.4050", search="Milano Centrale", country="DE")
153
+
154
+ # Handle response
155
+ print(res)
156
+ ```
157
+
158
+ </br>
159
+
160
+ The same SDK client can also be used to make asynchronous requests by importing asyncio.
161
+
162
+ ```python
163
+ # Asynchronous Example
164
+ import asyncio
165
+ import os
166
+ from train_travel import TrainTravel
167
+
168
+ async def main():
169
+
170
+ async with TrainTravel(
171
+ o_auth2=os.getenv("TRAINTRAVEL_O_AUTH2", ""),
172
+ ) as tt_client:
173
+
174
+ res = await tt_client.stations.get_stations_async(page=1, limit=10, coordinates="52.5200,13.4050", search="Milano Centrale", country="DE")
175
+
176
+ # Handle response
177
+ print(res)
178
+
179
+ asyncio.run(main())
180
+ ```
181
+ <!-- End SDK Example Usage [usage] -->
182
+
183
+ <!-- Start Authentication [security] -->
184
+ ## Authentication
185
+
186
+ ### Per-Client Security Schemes
187
+
188
+ This SDK supports the following security scheme globally:
189
+
190
+ | Name | Type | Scheme | Environment Variable |
191
+ | --------- | ------ | ------------ | --------------------- |
192
+ | `o_auth2` | oauth2 | OAuth2 token | `TRAINTRAVEL_O_AUTH2` |
193
+
194
+ To authenticate with the API the `o_auth2` parameter must be set when initializing the SDK client instance. For example:
195
+ ```python
196
+ import os
197
+ from train_travel import TrainTravel
198
+
199
+
200
+ with TrainTravel(
201
+ o_auth2=os.getenv("TRAINTRAVEL_O_AUTH2", ""),
202
+ ) as tt_client:
203
+
204
+ res = tt_client.stations.get_stations(page=1, limit=10, coordinates="52.5200,13.4050", search="Milano Centrale", country="DE")
205
+
206
+ # Handle response
207
+ print(res)
208
+
209
+ ```
210
+ <!-- End Authentication [security] -->
211
+
212
+ <!-- Start Available Resources and Operations [operations] -->
213
+ ## Available Resources and Operations
214
+
215
+ <details open>
216
+ <summary>Available methods</summary>
217
+
218
+ ### [Bookings](https://github.com/danielkov/train-travel/blob/master/train-travel-python/docs/sdks/bookings/README.md)
219
+
220
+ * [get_bookings](https://github.com/danielkov/train-travel/blob/master/train-travel-python/docs/sdks/bookings/README.md#get_bookings) - List existing bookings
221
+ * [create_booking](https://github.com/danielkov/train-travel/blob/master/train-travel-python/docs/sdks/bookings/README.md#create_booking) - Create a booking
222
+ * [create_booking_raw](https://github.com/danielkov/train-travel/blob/master/train-travel-python/docs/sdks/bookings/README.md#create_booking_raw) - Create a booking
223
+ * [get_booking](https://github.com/danielkov/train-travel/blob/master/train-travel-python/docs/sdks/bookings/README.md#get_booking) - Get a booking
224
+ * [delete_booking](https://github.com/danielkov/train-travel/blob/master/train-travel-python/docs/sdks/bookings/README.md#delete_booking) - Delete a booking
225
+
226
+ ### [Payments](https://github.com/danielkov/train-travel/blob/master/train-travel-python/docs/sdks/payments/README.md)
227
+
228
+ * [create_booking_payment](https://github.com/danielkov/train-travel/blob/master/train-travel-python/docs/sdks/payments/README.md#create_booking_payment) - Pay for a Booking
229
+
230
+ ### [Stations](https://github.com/danielkov/train-travel/blob/master/train-travel-python/docs/sdks/stations/README.md)
231
+
232
+ * [get_stations](https://github.com/danielkov/train-travel/blob/master/train-travel-python/docs/sdks/stations/README.md#get_stations) - Get a list of train stations
233
+
234
+ ### [Trips](https://github.com/danielkov/train-travel/blob/master/train-travel-python/docs/sdks/trips/README.md)
235
+
236
+ * [get_trips](https://github.com/danielkov/train-travel/blob/master/train-travel-python/docs/sdks/trips/README.md#get_trips) - Get available train trips
237
+
238
+ </details>
239
+ <!-- End Available Resources and Operations [operations] -->
240
+
241
+ <!-- Start File uploads [file-upload] -->
242
+ ## File uploads
243
+
244
+ Certain SDK methods accept file objects as part of a request body or multi-part request. It is possible and typically recommended to upload files as a stream rather than reading the entire contents into memory. This avoids excessive memory consumption and potentially crashing with out-of-memory errors when working with very large files. The following example demonstrates how to attach a file stream to a request.
245
+
246
+ > [!TIP]
247
+ >
248
+ > For endpoints that handle file uploads bytes arrays can also be used. However, using streams is recommended for large files.
249
+ >
250
+
251
+ ```python
252
+ import io
253
+ import os
254
+ from train_travel import TrainTravel
255
+
256
+
257
+ with TrainTravel(
258
+ o_auth2=os.getenv("TRAINTRAVEL_O_AUTH2", ""),
259
+ ) as tt_client:
260
+
261
+ res = tt_client.bookings.create_booking_raw(request=io.BytesIO("{\"trip_id\":\"4f4e4e1-c824-4d63-b37a-d8d698862f1d\",\"passenger_name\":\"John Doe\"}".encode()))
262
+
263
+ # Handle response
264
+ print(res)
265
+
266
+ ```
267
+ <!-- End File uploads [file-upload] -->
268
+
269
+ <!-- Start Retries [retries] -->
270
+ ## Retries
271
+
272
+ Some of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.
273
+
274
+ To change the default retry strategy for a single API call, simply provide a `RetryConfig` object to the call:
275
+ ```python
276
+ import os
277
+ from train_travel import TrainTravel
278
+ from train_travel.utils import BackoffStrategy, RetryConfig
279
+
280
+
281
+ with TrainTravel(
282
+ o_auth2=os.getenv("TRAINTRAVEL_O_AUTH2", ""),
283
+ ) as tt_client:
284
+
285
+ res = tt_client.stations.get_stations(page=1, limit=10, coordinates="52.5200,13.4050", search="Milano Centrale", country="DE",
286
+ RetryConfig("backoff", BackoffStrategy(1, 50, 1.1, 100), False))
287
+
288
+ # Handle response
289
+ print(res)
290
+
291
+ ```
292
+
293
+ If you'd like to override the default retry strategy for all operations that support retries, you can use the `retry_config` optional parameter when initializing the SDK:
294
+ ```python
295
+ import os
296
+ from train_travel import TrainTravel
297
+ from train_travel.utils import BackoffStrategy, RetryConfig
298
+
299
+
300
+ with TrainTravel(
301
+ retry_config=RetryConfig("backoff", BackoffStrategy(1, 50, 1.1, 100), False),
302
+ o_auth2=os.getenv("TRAINTRAVEL_O_AUTH2", ""),
303
+ ) as tt_client:
304
+
305
+ res = tt_client.stations.get_stations(page=1, limit=10, coordinates="52.5200,13.4050", search="Milano Centrale", country="DE")
306
+
307
+ # Handle response
308
+ print(res)
309
+
310
+ ```
311
+ <!-- End Retries [retries] -->
312
+
313
+ <!-- Start Error Handling [errors] -->
314
+ ## Error Handling
315
+
316
+ [`TrainTravelError`](https://github.com/danielkov/train-travel/blob/master/train-travel-python/./src/train_travel/errors/traintravelerror.py) is the base class for all HTTP error responses. It has the following properties:
317
+
318
+ | Property | Type | Description |
319
+ | ------------------ | ---------------- | ------------------------------------------------------ |
320
+ | `err.message` | `str` | Error message |
321
+ | `err.status_code` | `int` | HTTP response status code eg `404` |
322
+ | `err.headers` | `httpx.Headers` | HTTP response headers |
323
+ | `err.body` | `str` | HTTP body. Can be empty string if no body is returned. |
324
+ | `err.raw_response` | `httpx.Response` | Raw HTTP response |
325
+
326
+ ### Example
327
+ ```python
328
+ import os
329
+ from train_travel import TrainTravel, errors
330
+
331
+
332
+ with TrainTravel(
333
+ o_auth2=os.getenv("TRAINTRAVEL_O_AUTH2", ""),
334
+ ) as tt_client:
335
+ res = None
336
+ try:
337
+
338
+ res = tt_client.stations.get_stations(page=1, limit=10, coordinates="52.5200,13.4050", search="Milano Centrale", country="DE")
339
+
340
+ # Handle response
341
+ print(res)
342
+
343
+
344
+ except errors.TrainTravelError as e:
345
+ # The base class for HTTP error responses
346
+ print(e.message)
347
+ print(e.status_code)
348
+ print(e.body)
349
+ print(e.headers)
350
+ print(e.raw_response)
351
+
352
+ ```
353
+
354
+ ### Error Classes
355
+ **Primary error:**
356
+ * [`TrainTravelError`](https://github.com/danielkov/train-travel/blob/master/train-travel-python/./src/train_travel/errors/traintravelerror.py): The base class for HTTP error responses.
357
+
358
+ <details><summary>Less common errors (5)</summary>
359
+
360
+ <br />
361
+
362
+ **Network errors:**
363
+ * [`httpx.RequestError`](https://www.python-httpx.org/exceptions/#httpx.RequestError): Base class for request errors.
364
+ * [`httpx.ConnectError`](https://www.python-httpx.org/exceptions/#httpx.ConnectError): HTTP client was unable to make a request to a server.
365
+ * [`httpx.TimeoutException`](https://www.python-httpx.org/exceptions/#httpx.TimeoutException): HTTP request timed out.
366
+
367
+
368
+ **Inherit from [`TrainTravelError`](https://github.com/danielkov/train-travel/blob/master/train-travel-python/./src/train_travel/errors/traintravelerror.py)**:
369
+ * [`ResponseValidationError`](https://github.com/danielkov/train-travel/blob/master/train-travel-python/./src/train_travel/errors/responsevalidationerror.py): Type mismatch between the response data and the expected Pydantic model. Provides access to the Pydantic validation error via the `cause` attribute.
370
+
371
+ </details>
372
+ <!-- End Error Handling [errors] -->
373
+
374
+ <!-- Start Server Selection [server] -->
375
+ ## Server Selection
376
+
377
+ ### Select Server by Index
378
+
379
+ You can override the default server globally by passing a server index to the `server_idx: int` optional parameter when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the indexes associated with the available servers:
380
+
381
+ | # | Server | Description |
382
+ | --- | ----------------------------------------------------- | ----------- |
383
+ | 0 | `https://try.microcks.io/rest/Train+Travel+API/1.0.0` | Mock Server |
384
+ | 1 | `https://api.example.com` | Production |
385
+
386
+ #### Example
387
+
388
+ ```python
389
+ import os
390
+ from train_travel import TrainTravel
391
+
392
+
393
+ with TrainTravel(
394
+ server_idx=0,
395
+ o_auth2=os.getenv("TRAINTRAVEL_O_AUTH2", ""),
396
+ ) as tt_client:
397
+
398
+ res = tt_client.stations.get_stations(page=1, limit=10, coordinates="52.5200,13.4050", search="Milano Centrale", country="DE")
399
+
400
+ # Handle response
401
+ print(res)
402
+
403
+ ```
404
+
405
+ ### Override Server URL Per-Client
406
+
407
+ The default server can also be overridden globally by passing a URL to the `server_url: str` optional parameter when initializing the SDK client instance. For example:
408
+ ```python
409
+ import os
410
+ from train_travel import TrainTravel
411
+
412
+
413
+ with TrainTravel(
414
+ server_url="https://api.example.com",
415
+ o_auth2=os.getenv("TRAINTRAVEL_O_AUTH2", ""),
416
+ ) as tt_client:
417
+
418
+ res = tt_client.stations.get_stations(page=1, limit=10, coordinates="52.5200,13.4050", search="Milano Centrale", country="DE")
419
+
420
+ # Handle response
421
+ print(res)
422
+
423
+ ```
424
+ <!-- End Server Selection [server] -->
425
+
426
+ <!-- Start Custom HTTP Client [http-client] -->
427
+ ## Custom HTTP Client
428
+
429
+ The Python SDK makes API calls using the [httpx](https://www.python-httpx.org/) HTTP library. In order to provide a convenient way to configure timeouts, cookies, proxies, custom headers, and other low-level configuration, you can initialize the SDK client with your own HTTP client instance.
430
+ Depending on whether you are using the sync or async version of the SDK, you can pass an instance of `HttpClient` or `AsyncHttpClient` respectively, which are Protocol's ensuring that the client has the necessary methods to make API calls.
431
+ This allows you to wrap the client with your own custom logic, such as adding custom headers, logging, or error handling, or you can just pass an instance of `httpx.Client` or `httpx.AsyncClient` directly.
432
+
433
+ For example, you could specify a header for every request that this sdk makes as follows:
434
+ ```python
435
+ from train_travel import TrainTravel
436
+ import httpx
437
+
438
+ http_client = httpx.Client(headers={"x-custom-header": "someValue"})
439
+ s = TrainTravel(client=http_client)
440
+ ```
441
+
442
+ or you could wrap the client with your own custom logic:
443
+ ```python
444
+ from train_travel import TrainTravel
445
+ from train_travel.httpclient import AsyncHttpClient
446
+ import httpx
447
+
448
+ class CustomClient(AsyncHttpClient):
449
+ client: AsyncHttpClient
450
+
451
+ def __init__(self, client: AsyncHttpClient):
452
+ self.client = client
453
+
454
+ async def send(
455
+ self,
456
+ request: httpx.Request,
457
+ *,
458
+ stream: bool = False,
459
+ auth: Union[
460
+ httpx._types.AuthTypes, httpx._client.UseClientDefault, None
461
+ ] = httpx.USE_CLIENT_DEFAULT,
462
+ follow_redirects: Union[
463
+ bool, httpx._client.UseClientDefault
464
+ ] = httpx.USE_CLIENT_DEFAULT,
465
+ ) -> httpx.Response:
466
+ request.headers["Client-Level-Header"] = "added by client"
467
+
468
+ return await self.client.send(
469
+ request, stream=stream, auth=auth, follow_redirects=follow_redirects
470
+ )
471
+
472
+ def build_request(
473
+ self,
474
+ method: str,
475
+ url: httpx._types.URLTypes,
476
+ *,
477
+ content: Optional[httpx._types.RequestContent] = None,
478
+ data: Optional[httpx._types.RequestData] = None,
479
+ files: Optional[httpx._types.RequestFiles] = None,
480
+ json: Optional[Any] = None,
481
+ params: Optional[httpx._types.QueryParamTypes] = None,
482
+ headers: Optional[httpx._types.HeaderTypes] = None,
483
+ cookies: Optional[httpx._types.CookieTypes] = None,
484
+ timeout: Union[
485
+ httpx._types.TimeoutTypes, httpx._client.UseClientDefault
486
+ ] = httpx.USE_CLIENT_DEFAULT,
487
+ extensions: Optional[httpx._types.RequestExtensions] = None,
488
+ ) -> httpx.Request:
489
+ return self.client.build_request(
490
+ method,
491
+ url,
492
+ content=content,
493
+ data=data,
494
+ files=files,
495
+ json=json,
496
+ params=params,
497
+ headers=headers,
498
+ cookies=cookies,
499
+ timeout=timeout,
500
+ extensions=extensions,
501
+ )
502
+
503
+ s = TrainTravel(async_client=CustomClient(httpx.AsyncClient()))
504
+ ```
505
+ <!-- End Custom HTTP Client [http-client] -->
506
+
507
+ <!-- Start Resource Management [resource-management] -->
508
+ ## Resource Management
509
+
510
+ The `TrainTravel` class implements the context manager protocol and registers a finalizer function to close the underlying sync and async HTTPX clients it uses under the hood. This will close HTTP connections, release memory and free up other resources held by the SDK. In short-lived Python programs and notebooks that make a few SDK method calls, resource management may not be a concern. However, in longer-lived programs, it is beneficial to create a single SDK instance via a [context manager][context-manager] and reuse it across the application.
511
+
512
+ [context-manager]: https://docs.python.org/3/reference/datamodel.html#context-managers
513
+
514
+ ```python
515
+ import os
516
+ from train_travel import TrainTravel
517
+ def main():
518
+
519
+ with TrainTravel(
520
+ o_auth2=os.getenv("TRAINTRAVEL_O_AUTH2", ""),
521
+ ) as tt_client:
522
+ # Rest of application here...
523
+
524
+
525
+ # Or when using async:
526
+ async def amain():
527
+
528
+ async with TrainTravel(
529
+ o_auth2=os.getenv("TRAINTRAVEL_O_AUTH2", ""),
530
+ ) as tt_client:
531
+ # Rest of application here...
532
+ ```
533
+ <!-- End Resource Management [resource-management] -->
534
+
535
+ <!-- Start Debugging [debug] -->
536
+ ## Debugging
537
+
538
+ You can setup your SDK to emit debug logs for SDK requests and responses.
539
+
540
+ You can pass your own logger class directly into your SDK.
541
+ ```python
542
+ from train_travel import TrainTravel
543
+ import logging
544
+
545
+ logging.basicConfig(level=logging.DEBUG)
546
+ s = TrainTravel(debug_logger=logging.getLogger("train_travel"))
547
+ ```
548
+
549
+ You can also enable a default debug logger by setting an environment variable `TRAINTRAVEL_DEBUG` to true.
550
+ <!-- End Debugging [debug] -->
551
+
552
+ <!-- Placeholder for Future Speakeasy SDK Sections -->
553
+
554
+ # Development
555
+
556
+ ## Maturity
557
+
558
+ This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage
559
+ to a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally
560
+ looking for the latest version.
561
+
562
+ ## Contributions
563
+
564
+ While we value open-source contributions to this SDK, this library is generated programmatically. Any manual changes added to internal files will be overwritten on the next generation.
565
+ We look forward to hearing your feedback. Feel free to open a PR or an issue with a proof of concept and we'll do our best to include it in a future release.
566
+
567
+ ### SDK Created by [Speakeasy](https://www.speakeasy.com/?utm_source=train-travel&utm_campaign=python)