Debian Codegraph @

PKG-INFO

raw
1 Metadata-Version: 2.4
2 Name: stripe
3 Version: 14.4.1
4 Summary: Python bindings for the Stripe API
5 Keywords: stripe,api,payments
6 Author-email: Stripe <[email protected]>
7 Requires-Python: >=3.7
8 Description-Content-Type: text/markdown
9 Classifier: Development Status :: 5 - Production/Stable
10 Classifier: Intended Audience :: Developers
11 Classifier: License :: OSI Approved :: MIT License
12 Classifier: Operating System :: OS Independent
13 Classifier: Programming Language :: Python
14 Classifier: Programming Language :: Python :: 3
15 Classifier: Programming Language :: Python :: 3 :: Only
16 Classifier: Programming Language :: Python :: 3.7
17 Classifier: Programming Language :: Python :: 3.8
18 Classifier: Programming Language :: Python :: 3.9
19 Classifier: Programming Language :: Python :: 3.10
20 Classifier: Programming Language :: Python :: 3.11
21 Classifier: Programming Language :: Python :: 3.12
22 Classifier: Programming Language :: Python :: Implementation :: CPython
23 Classifier: Programming Language :: Python :: Implementation :: PyPy
24 Classifier: Topic :: Software Development :: Libraries :: Python Modules
25 License-File: LICENSE
26 Requires-Dist: typing_extensions <= 4.2.0, > 3.7.2; python_version < '3.7'
27 Requires-Dist: typing_extensions >= 4.5.0; python_version >= '3.7'
28 Requires-Dist: requests >= 2.20; python_version >= '3.0'
29 Requires-Dist: httpx ; extra == "async"
30 Project-URL: changelog, https://github.com/stripe/stripe-python/blob/master/CHANGELOG.md
31 Project-URL: documentation, https://stripe.com/docs/api/?lang=python
32 Project-URL: homepage, https://stripe.com/
33 Project-URL: issues, https://github.com/stripe/stripe-python/issues
34 Project-URL: source, https://github.com/stripe/stripe-python
35 Provides-Extra: async
36
37 # Stripe Python Library
38
39 [![pypi](https://img.shields.io/pypi/v/stripe.svg)](https://pypi.python.org/pypi/stripe)
40 [![Build Status](https://github.com/stripe/stripe-python/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/stripe/stripe-python/actions?query=branch%3Amaster)
41
42 The Stripe Python library provides convenient access to the Stripe API from
43 applications written in the Python language. It includes a pre-defined set of
44 classes for API resources that initialize themselves dynamically from API
45 responses which makes it compatible with a wide range of versions of the Stripe
46 API.
47
48 ## API Documentation
49
50 See the [Python API docs](https://stripe.com/docs/api?lang=python).
51
52 ## Installation
53
54 This package is available on PyPI:
55
56 ```sh
57 pip install --upgrade stripe
58 ```
59
60 Alternatively, install from source with:
61
62 ```sh
63 python -m pip install .
64 ```
65
66 ### Requirements
67
68 Per our [Language Version Support Policy](https://docs.stripe.com/sdks/versioning?lang=python#stripe-sdk-language-version-support-policy), we currently support **Python 3.7+**.
69
70 Support for Python 3.7 and 3.8 is deprecated and will be removed in an upcoming major version. Read more and see the full schedule in the docs: https://docs.stripe.com/sdks/versioning?lang=python#stripe-sdk-language-version-support-policy
71
72 #### Extended Support
73
74 #### Python 2.7 deprecation
75
76 [The Python Software Foundation (PSF)](https://www.python.org/psf-landing/) community [announced the end of support of Python 2](https://www.python.org/doc/sunset-python-2/) on 01 January 2020.
77 Starting with version 6.0.0 Stripe SDK Python packages will no longer support Python 2.7. To continue to get new features and security updates, please make sure to update your Python runtime to Python 3.6+.
78
79 The last version of the Stripe SDK that supported Python 2.7 was **5.5.0**.
80
81 ## Usage
82
83 The library needs to be configured with your account's secret key which is
84 available in your [Stripe Dashboard][api-keys]. Set `stripe.api_key` to its
85 value:
86
87 ```python
88 from stripe import StripeClient
89
90 client = StripeClient("sk_test_...")
91
92 # list customers
93 customers = client.v1.customers.list()
94
95 # print the first customer's email
96 print(customers.data[0].email)
97
98 # retrieve specific Customer
99 customer = client.v1.customers.retrieve("cus_123456789")
100
101 # print that customer's email
102 print(customer.email)
103 ```
104
105 ### StripeClient vs legacy pattern
106
107 We introduced the `StripeClient` class in v8 of the Python SDK. The legacy pattern used prior to that version is still available to use but will be marked as deprecated soon. Review the [migration guide to use StripeClient](<https://github.com/stripe/stripe-python/wiki/Migration-guide-for-v8-(StripeClient)>) to move from the legacy pattern.
108
109 Once the legacy pattern is deprecated, new API endpoints will only be accessible in the StripeClient. While there are no current plans to remove the legacy pattern for existing API endpoints, this may change in the future.
110
111 ### Handling exceptions
112
113 Unsuccessful requests raise exceptions. The class of the exception will reflect
114 the sort of error that occurred. Please see the [Api
115 Reference](https://stripe.com/docs/api/errors/handling) for a description of
116 the error classes you should handle, and for information on how to inspect
117 these errors.
118
119 ### Per-request Configuration
120
121 Configure individual requests with the `options` argument. For example, you can make
122 requests with a specific [Stripe Version](https://stripe.com/docs/api#versioning)
123 or as a [connected account](https://stripe.com/docs/connect/authentication#authentication-via-the-stripe-account-header):
124
125 ```python
126 from stripe import StripeClient
127
128 client = StripeClient("sk_test_...")
129
130 # list customers
131 client.v1.customers.list(
132 options={
133 "api_key": "sk_test_...",
134 "stripe_account": "acct_...",
135 "stripe_version": "2019-02-19",
136 }
137 )
138
139 # retrieve single customer
140 client.v1.customers.retrieve(
141 "cus_123456789",
142 options={
143 "api_key": "sk_test_...",
144 "stripe_account": "acct_...",
145 "stripe_version": "2019-02-19",
146 }
147 )
148 ```
149
150 ### Configuring an HTTP Client
151
152 You can configure your `StripeClient` to use `urlfetch`, `requests`, `pycurl`, or
153 `urllib` with the `http_client` option:
154
155 ```python
156 client = StripeClient("sk_test_...", http_client=stripe.UrlFetchClient())
157 client = StripeClient("sk_test_...", http_client=stripe.RequestsClient())
158 client = StripeClient("sk_test_...", http_client=stripe.PycurlClient())
159 client = StripeClient("sk_test_...", http_client=stripe.UrllibClient())
160 ```
161
162 Without a configured client, by default the library will attempt to load
163 libraries in the order above (i.e. `urlfetch` is preferred with `urllib2` used
164 as a last resort). We usually recommend that people use `requests`.
165
166 ### Configuring a Proxy
167
168 A proxy can be configured with the `proxy` client option:
169
170 ```python
171 client = StripeClient("sk_test_...", proxy="https://user:[email protected]:1234")
172 ```
173
174 ### Configuring Automatic Retries
175
176 You can enable automatic retries on requests that fail due to a transient
177 problem by configuring the maximum number of retries:
178
179 ```python
180 client = StripeClient("sk_test_...", max_network_retries=2)
181 ```
182
183 Various errors can trigger a retry, like a connection error or a timeout, and
184 also certain API responses like HTTP status `409 Conflict`.
185
186 [Idempotency keys][idempotency-keys] are automatically generated and added to
187 requests, when not given, to guarantee that retries are safe.
188
189 ### Logging
190
191 The library can be configured to emit logging that will give you better insight
192 into what it's doing. The `info` logging level is usually most appropriate for
193 production use, but `debug` is also available for more verbosity.
194
195 There are a few options for enabling it:
196
197 1. Set the environment variable `STRIPE_LOG` to the value `debug` or `info`
198
199 ```sh
200 $ export STRIPE_LOG=debug
201 ```
202
203 2. Set `stripe.log`:
204
205 ```python
206 import stripe
207 stripe.log = 'debug'
208 ```
209
210 3. Enable it through Python's logging module:
211
212 ```python
213 import logging
214 logging.basicConfig()
215 logging.getLogger('stripe').setLevel(logging.DEBUG)
216 ```
217
218 ### Accessing response code and headers
219
220 You can access the HTTP response code and headers using the `last_response` property of the returned resource.
221
222 ```python
223 customer = client.v1.customers.retrieve(
224 "cus_123456789"
225 )
226
227 print(customer.last_response.code)
228 print(customer.last_response.headers)
229 ```
230
231 ### How to use undocumented parameters and properties
232
233 In some cases, you might encounter parameters on an API request or fields on an API response that aren’t available in the SDKs.
234 This might happen when they’re undocumented or when they’re in preview and you aren’t using a preview SDK.
235 See [undocumented params and properties](https://docs.stripe.com/sdks/server-side?lang=python#undocumented-params-and-fields) to send those parameters or access those fields.
236
237 ### Writing a Plugin
238
239 If you're writing a plugin that uses the library, we'd appreciate it if you
240 identified using `stripe.set_app_info()`:
241
242 ```py
243 stripe.set_app_info("MyAwesomePlugin", version="1.2.34", url="https://myawesomeplugin.info")
244 ```
245
246 This information is passed along when the library makes calls to the Stripe
247 API.
248
249 ### Telemetry
250
251 By default, the library sends telemetry to Stripe regarding request latency and feature usage. These
252 numbers help Stripe improve the overall latency of its API for all users, and
253 improve popular features.
254
255 You can disable this behavior if you prefer:
256
257 ```python
258 stripe.enable_telemetry = False
259 ```
260
261 ## Types
262
263 In [v7.1.0](https://github.com/stripe/stripe-python/releases/tag/v7.1.0) and
264 newer, the
265 library includes type annotations. See [the wiki](https://github.com/stripe/stripe-python/wiki/Inline-type-annotations)
266 for a detailed guide.
267
268 Please note that some annotations use features that were only fairly recently accepted,
269 such as [`Unpack[TypedDict]`](https://peps.python.org/pep-0692/#specification) that was
270 [accepted](https://discuss.python.org/t/pep-692-using-typeddict-for-more-precise-kwargs-typing/17314/81)
271 in January 2023. We have tested that these types are recognized properly by [Pyright](https://github.com/microsoft/pyright).
272 Support for `Unpack` in MyPy is still experimental, but appears to degrade gracefully.
273 Please [report an issue](https://github.com/stripe/stripe-python/issues/new/choose) if there
274 is anything we can do to improve the types for your type checker of choice.
275
276 ### Types and the Versioning Policy
277
278 We release type changes in minor releases. While stripe-python follows semantic
279 versioning, our semantic versions describe the _runtime behavior_ of the
280 library alone. Our _type annotations are not reflected in the semantic
281 version_. That is, upgrading to a new minor version of stripe-python might
282 result in your type checker producing a type error that it didn't before. You
283 can use a `~=x.x` or `x.x.*` [version specifier](https://peps.python.org/pep-0440/#examples)
284 in your `requirements.txt` to constrain `pip` to a certain minor range of `stripe-python`.
285
286 ### Types and API Versions
287
288 The types describe the [Stripe API version](https://stripe.com/docs/api/versioning)
289 that was the latest at the time of release. This is the version that your library
290 sends by default. If you are overriding `stripe.api_version` / `stripe_version` on the `StripeClient`, or using a
291 [webhook endpoint](https://stripe.com/docs/webhooks#api-versions) tied to an older version,
292 be aware that the data you see at runtime may not match the types.
293
294 ### Public Preview SDKs
295
296 Stripe has features in the [public preview phase](https://docs.stripe.com/release-phases) that can be accessed via versions of this package that have the `bX` suffix like `12.2.0b2`.
297 We would love for you to try these as we incrementally release new features and improve them based on your feedback.
298
299 To install, pick the latest version with the `bX` suffix by reviewing the [releases page](https://github.com/stripe/stripe-python/releases/) and then use it in the `pip install` command:
300
301 ```
302 pip install stripe==<replace-with-the-version-of-your-choice>
303 ```
304
305 > **Note**
306 > There can be breaking changes between two versions of the public preview SDKs without a bump in the major version. Therefore we recommend pinning the package version to a specific version in your [pyproject.toml](https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#dependencies-and-requirements) or [requirements file](https://pip.pypa.io/en/stable/user_guide/#requirements-files). This way you can install the same version each time without breaking changes unless you are intentionally looking for the latest public preview SDK.
307
308 Some preview features require a name and version to be set in the `Stripe-Version` header like `feature_beta=v3`. If your preview feature has this requirement, use the `stripe.add_beta_version` function (available only in the public preview SDKs):
309
310 ```python
311 stripe.add_beta_version("feature_beta", "v3")
312 ```
313
314 ### Private Preview SDKs
315
316 Stripe has features in the [private preview phase](https://docs.stripe.com/release-phases) that can be accessed via versions of this package that have the `aX` suffix like `12.2.0a2`. These are invite-only features. Once invited, you can install the private preview SDKs by following the same instructions as for the [public preview SDKs](https://github.com/stripe/stripe-python?tab=readme-ov-file#public-preview-sdks) above and replacing the suffix `b` with `a` in package versions.
317
318 ### Custom requests
319
320 > This feature is only available from version 11 of this SDK.
321
322 If you would like to send a request to an undocumented API (for example you are in a private beta), or if you prefer to bypass the method definitions in the library and specify your request details directly, you can use the `raw_request` method on `StripeClient`.
323
324 ```python
325 client = StripeClient("sk_test_...")
326 response = client.raw_request(
327 "post", "/v1/beta_endpoint", param=123, stripe_version="2022-11-15; feature_beta=v3"
328 )
329
330 # (Optional) response is a StripeResponse. You can use `client.deserialize` to get a StripeObject.
331 deserialized_resp = client.deserialize(response, api_mode='V1')
332 ```
333
334 ### Async
335
336 Asynchronous versions of request-making methods are available by suffixing the method name
337 with `_async`.
338
339 ```python
340 # With StripeClient
341 client = StripeClient("sk_test_...")
342 customer = await client.v1.customers.retrieve_async("cus_xyz")
343
344 # With global client
345 stripe.api_key = "sk_test_..."
346 customer = await stripe.Customer.retrieve_async("cus_xyz")
347
348 # .auto_paging_iter() implements both AsyncIterable and Iterable
349 async for c in await stripe.Customer.list_async().auto_paging_iter():
350 ...
351 ```
352
353 There is no `.save_async` as `.save` is [deprecated since stripe-python v5](https://github.com/stripe/stripe-python/wiki/Migration-guide-for-v5#deprecated). Please migrate to `.modify_async`.
354
355 The default HTTP client uses `requests` for making synchronous requests but
356 `httpx` for making async requests. If you're migrating to async, we recommend
357 you to explicitly initialize your own http client and pass it to StripeClient
358 or set it as the global default.
359
360 If you don't already have a dependency on an async-compatible HTTP library, `pip install stripe[async]` will install one for you (new in `v13.0.1`).
361
362 ```python
363 # By default, an explicitly initialized HTTPXClient will raise an exception if you
364 # attempt to call a sync method. If you intend to only use async, this is useful to
365 # make sure you don't unintentionally make a synchronous request.
366 my_http_client = stripe.HTTPXClient()
367
368 # If you want to use httpx to make sync requests, you can disable this
369 # behavior.
370 my_http_client = stripe.HTTPXClient(allow_sync_methods=True)
371
372 # aiohttp is also available (does not support sync requests)
373 my_http_client = stripe.AIOHTTPClient()
374
375 # With StripeClient
376 client = StripeClient("sk_test_...", http_client=my_http_client)
377
378 # With the global client
379 stripe.default_http_client = my_http_client
380 ```
381
382 You can also subclass `stripe.HTTPClient` and provide your own instance.
383
384 ## Support
385
386 New features and bug fixes are released on the latest major version of the Stripe Python library. If you are on an older major version, we recommend that you upgrade to the latest in order to use the new features and bug fixes including those for security vulnerabilities. Older major versions of the package will continue to be available for use, but will not be receiving any updates.
387
388 ## Development
389
390 [Contribution guidelines for this project](CONTRIBUTING.md)
391
392 The test suite depends on [stripe-mock], so make sure to fetch and run it from a
393 background terminal ([stripe-mock's README][stripe-mock] also contains
394 instructions for installing via Homebrew and other methods):
395
396 ```sh
397 go install github.com/stripe/stripe-mock@latest
398 stripe-mock
399 ```
400
401 We use [just](https://github.com/casey/just) for conveniently running development tasks. You can use them directly, or copy the commands out of the `justfile`. To our help docs, run `just`. By default, all commands will use an virtualenv created by your default python version (whatever comes out of `python --version`). We recommend using [mise](https://mise.jdx.dev/lang/python.html) or [pyenv](https://github.com/pyenv/pyenv) to control that version.
402
403 Run the following command to set up the development virtualenv:
404
405 ```sh
406 just venv
407 # or: python -m venv venv && venv/bin/python -I -m pip install -e .
408 ```
409
410 Run all tests:
411
412 ```sh
413 just test
414 # or: venv/bin/pytest
415 ```
416
417 Run all tests in a single file:
418
419 ```sh
420 just test tests/api_resources/abstract/test_updateable_api_resource.py
421 # or: venv/bin/pytest tests/api_resources/abstract/test_updateable_api_resource.py
422 ```
423
424 Run a single test suite:
425
426 ```sh
427 just test tests/api_resources/abstract/test_updateable_api_resource.py::TestUpdateableAPIResource
428 # or: venv/bin/pytest tests/api_resources/abstract/test_updateable_api_resource.py::TestUpdateableAPIResource
429 ```
430
431 Run a single test:
432
433 ```sh
434 just test tests/api_resources/abstract/test_updateable_api_resource.py::TestUpdateableAPIResource::test_save
435 # or: venv/bin/pytest tests/api_resources/abstract/test_updateable_api_resource.py::TestUpdateableAPIResource::test_save
436 ```
437
438 Run the linter with:
439
440 ```sh
441 just lint
442 # or: venv/bin/python -m flake8 --show-source stripe tests
443 ```
444
445 The library uses [Ruff][ruff] for code formatting. Code must be formatted
446 with Black before PRs are submitted, otherwise CI will fail. Run the formatter
447 with:
448
449 ```sh
450 just format
451 # or: venv/bin/ruff format . --quiet
452 ```
453
454 Update bundled CA certificates from the [Mozilla cURL release][curl]:
455
456 ```sh
457 just update-certs
458 ```
459
460 [api-keys]: https://dashboard.stripe.com/account/apikeys
461 [ruff]: https://github.com/astral-sh/ruff
462 [connect]: https://stripe.com/connect
463 [poetry]: https://github.com/sdispater/poetry
464 [stripe-mock]: https://github.com/stripe/stripe-mock
465 [idempotency-keys]: https://stripe.com/docs/api/idempotent_requests?lang=python
466
467 <!--
468 # vim: set tw=79:
469 -->
470