• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

stripe/H04-Jun-2019-8,4497,059

stripe.egg-info/H03-May-2022-6548

tests/H04-Jun-2019-7,4855,876

.coveragercH A D25-Mar-201947 54

.flake8H A D25-Mar-2019361 119

CHANGELOG.mdH A D04-Jun-201923.2 KiB612427

LICENSEH A D25-Mar-20191.1 KiB2217

LONG_DESCRIPTION.rstH A D25-Mar-2019936 3519

MANIFEST.inH A D04-Jun-2019136 32

PKG-INFOH A D04-Jun-20192.4 KiB6548

README.mdH A D04-Jun-20195.5 KiB203137

VERSIONH A D04-Jun-20197 21

setup.cfgH A D04-Jun-2019102 117

setup.pyH A D04-Jun-20192.9 KiB8973

tox.iniH A D04-Jun-2019844 3227

README.md

1# Stripe Python Library
2
3[![Build Status](https://travis-ci.org/stripe/stripe-python.svg?branch=master)](https://travis-ci.org/stripe/stripe-python)
4[![Coverage Status](https://coveralls.io/repos/github/stripe/stripe-python/badge.svg?branch=master)](https://coveralls.io/github/stripe/stripe-python?branch=master)
5
6The Stripe Python library provides convenient access to the Stripe API from
7applications written in the Python language. It includes a pre-defined set of
8classes for API resources that initialize themselves dynamically from API
9responses which makes it compatible with a wide range of versions of the Stripe
10API.
11
12## Documentation
13
14See the [Python API docs](https://stripe.com/docs/api/python#intro).
15
16## Installation
17
18You don't need this source code unless you want to modify the package. If you just
19want to use the package, just run:
20
21    pip install --upgrade stripe
22
23Install from source with:
24
25    python setup.py install
26
27### Requirements
28
29- Python 2.7+ or Python 3.4+ (PyPy supported)
30
31## Usage
32
33The library needs to be configured with your account's secret key which is
34available in your [Stripe Dashboard][api-keys]. Set `stripe.api_key` to its
35value:
36
37```python
38import stripe
39stripe.api_key = "sk_test_..."
40
41# list charges
42stripe.Charge.list()
43
44# retrieve single charge
45stripe.Charge.retrieve("ch_1A2PUG2eZvKYlo2C4Rej1B9d")
46```
47
48### Per-request Configuration
49
50Configure individual requests with keyword arguments. For example, you can make
51requests with a specific [Stripe Version](https://stripe.com/docs/api#versioning)
52or as a [connected account](https://stripe.com/docs/connect/authentication#authentication-via-the-stripe-account-header):
53
54```python
55import stripe
56
57# list charges
58stripe.Charge.list(
59    api_key="sk_test_...",
60    stripe_account="acct_...",
61    stripe_version="2019-02-19"
62)
63
64# retrieve single charge
65stripe.Charge.retrieve(
66    "ch_1A2PUG2eZvKYlo2C4Rej1B9d",
67    api_key="sk_test_...",
68    stripe_account="acct_...",
69    stripe_version="2019-02-19"
70)
71```
72
73### Configuring a Client
74
75The library can be configured to use `urlfetch`, `requests`, `pycurl`, or
76`urllib2` with `stripe.default_http_client`:
77
78```python
79client = stripe.http_client.UrlFetchClient()
80client = stripe.http_client.RequestsClient()
81client = stripe.http_client.PycurlClient()
82client = stripe.http_client.Urllib2Client()
83stripe.default_http_client = client
84```
85
86Without a configured client, by default the library will attempt to load
87libraries in the order above (i.e. `urlfetch` is preferred with `urllib2` used
88as a last resort). We usually recommend that people use `requests`.
89
90### Configuring a Proxy
91
92A proxy can be configured with `stripe.proxy`:
93
94```python
95stripe.proxy = "https://user:pass@example.com:1234"
96```
97
98### Configuring Automatic Retries
99
100Number of automatic retries on requests that fail due to an intermittent
101network problem can be configured:
102
103```python
104stripe.max_network_retries = 2
105```
106
107[Idempotency keys][idempotency-keys] are automatically generated and added to
108requests, when not given, to guarantee that retries are safe.
109
110### Logging
111
112The library can be configured to emit logging that will give you better insight
113into what it's doing. The `info` logging level is usually most appropriate for
114production use, but `debug` is also available for more verbosity.
115
116There are a few options for enabling it:
117
1181. Set the environment variable `STRIPE_LOG` to the value `debug` or `info`
119
120   ```
121   $ export STRIPE_LOG=debug
122   ```
123
1242. Set `stripe.log`:
125
126   ```py
127   import stripe
128   stripe.log = 'debug'
129   ```
130
1313. Enable it through Python's logging module:
132   ```py
133   import logging
134   logging.basicConfig()
135   logging.getLogger('stripe').setLevel(logging.DEBUG)
136   ```
137
138### Writing a Plugin
139
140If you're writing a plugin that uses the library, we'd appreciate it if you
141identified using `stripe.set_app_info()`:
142
143```py
144stripe.set_app_info("MyAwesomePlugin", version="1.2.34", url="https://myawesomeplugin.info")
145```
146
147This information is passed along when the library makes calls to the Stripe
148API.
149
150## Development
151
152The test suite depends on [stripe-mock], so make sure to fetch and run it from a
153background terminal ([stripe-mock's README][stripe-mock] also contains
154instructions for installing via Homebrew and other methods):
155
156    go get -u github.com/stripe/stripe-mock
157    stripe-mock
158
159Run the following command to set up the development virtualenv:
160
161    make init
162
163Run all tests on all supported Python versions:
164
165    make test
166
167Run all tests for a specific Python version (modify `-e` according to your Python target):
168
169    TOX_ARGS="-e py27" make test
170
171Run all tests in a single file:
172
173    TOX_ARGS="-e py27 -- tests/api_resources/abstract/test_updateable_api_resource.py" make test
174
175Run a single test suite:
176
177    TOX_ARGS="-e py27 -- tests/api_resources/abstract/test_updateable_api_resource.py::TestUpdateableAPIResource" make test
178
179Run a single test:
180
181    TOX_ARGS="-e py27 -- tests/api_resources/abstract/test_updateable_api_resource.py::TestUpdateableAPIResource::test_save" make test
182
183Run the linter with:
184
185    make lint
186
187The library uses [Black][black] for code formatting. Code must be formatted
188with Black before PRs are submitted, otherwise CI will fail. Run the formatter
189with:
190
191    make fmt
192
193[api-keys]: https://dashboard.stripe.com/account/apikeys
194[black]: https://github.com/ambv/black
195[connect]: https://stripe.com/connect
196[poetry]: https://github.com/sdispater/poetry
197[stripe-mock]: https://github.com/stripe/stripe-mock
198[idempotency-keys]: https://stripe.com/docs/api/idempotent_requests?lang=python
199
200<!--
201# vim: set tw=79:
202-->
203