pyjs-extras 0.4.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.
@@ -0,0 +1,28 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2025, Lex Berezhny
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,88 @@
1
+ Metadata-Version: 2.4
2
+ Name: pyjs-extras
3
+ Version: 0.4.0
4
+ Summary: Official third-party integrations for PyJS.
5
+ Author-email: Lex Berezhny <lex@damoti.com>
6
+ License-Expression: BSD-3-Clause
7
+ Project-URL: Homepage, https://github.com/pyjs/pyjs
8
+ Project-URL: Source, https://github.com/pyjs/pyjs
9
+ Classifier: Development Status :: 2 - Pre-Alpha
10
+ Classifier: Environment :: Web Environment
11
+ Classifier: Intended Audience :: Developers
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.14
17
+ Classifier: Topic :: Internet :: WWW/HTTP
18
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
19
+ Requires-Python: >=3.14
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: pyjs==0.4.0
23
+ Provides-Extra: stripe
24
+ Requires-Dist: stripe<15,>=14; extra == "stripe"
25
+ Provides-Extra: test
26
+ Requires-Dist: pytest>=9.0; extra == "test"
27
+ Requires-Dist: stripe<15,>=14; extra == "test"
28
+ Dynamic: license-file
29
+
30
+ # PyJS Extras
31
+
32
+ `pyjs-extras` contains official, optional integrations between PyJS and
33
+ third-party services. Install only the provider dependencies you need:
34
+
35
+ ```console
36
+ uv add "pyjs-extras[stripe]"
37
+ ```
38
+
39
+ When the matching PyJS version is already a direct dependency, this convenience
40
+ spelling is equivalent:
41
+
42
+ ```console
43
+ uv add "pyjs[stripe]"
44
+ ```
45
+
46
+ ## Stripe
47
+
48
+ `pyjs_extras.stripe` provides five deliberately separate surfaces:
49
+
50
+ - `browser` contains typed Stripe.js declarations for transpiled code.
51
+ - `web` contains dependency-free SSR helpers for Stripe script and pricing
52
+ table elements.
53
+ - `server` adapts the official Python Stripe SDK without depending on a web
54
+ framework.
55
+ - `testing` provides an in-memory mock suitable for application tests.
56
+ - `simulator` runs a stateful local Stripe-compatible HTTP service for complete
57
+ Checkout, webhook, subscription, and customer-portal scenarios.
58
+
59
+ Business concepts such as members, entitlements, and local subscription models
60
+ belong in an application or membership package rather than this integration.
61
+
62
+ Start the simulator with an application webhook destination:
63
+
64
+ ```console
65
+ uv run pyjs-stripe-simulator \
66
+ --webhook-url http://localhost:8000/stripe/webhook/
67
+ ```
68
+
69
+ The API uses `sk_test_local`, webhooks use `whsec_local`, and state is stored in
70
+ `.pyjs-stripe.sqlite3` by default. Point `StripeGateway(api_base=...)` at
71
+ `http://127.0.0.1:12111` so application code follows the same SDK path used with
72
+ Stripe.
73
+
74
+ Open <http://127.0.0.1:12111> for the PyJS operator dashboard. It can select
75
+ successful, retryable-decline, hard-decline, or authentication-required
76
+ behavior for each subscription, run renewals, retry open invoices, advance the
77
+ clock, replace payment methods, and inspect invoice retry state. Webhook tools
78
+ can switch between automatic, manual, and paused forwarding; deliver pending
79
+ events oldest- or newest-first; send duplicate events; and inject invalid or
80
+ stale signatures. Test-only JSON state, reset, and clock controls remain
81
+ available under `/_test/`.
82
+
83
+ The simulator uses three payment attempts before marking a retryable invoice
84
+ uncollectible and its subscription unpaid. See
85
+ [`stripe/SIMULATOR.md`](stripe/SIMULATOR.md) for its lifecycle contract and
86
+ deliberate limits. Product, price, amount, currency, and maximum payment
87
+ attempts can be changed with command-line options; run
88
+ `pyjs-stripe-simulator --help` for the complete list.
@@ -0,0 +1,59 @@
1
+ # PyJS Extras
2
+
3
+ `pyjs-extras` contains official, optional integrations between PyJS and
4
+ third-party services. Install only the provider dependencies you need:
5
+
6
+ ```console
7
+ uv add "pyjs-extras[stripe]"
8
+ ```
9
+
10
+ When the matching PyJS version is already a direct dependency, this convenience
11
+ spelling is equivalent:
12
+
13
+ ```console
14
+ uv add "pyjs[stripe]"
15
+ ```
16
+
17
+ ## Stripe
18
+
19
+ `pyjs_extras.stripe` provides five deliberately separate surfaces:
20
+
21
+ - `browser` contains typed Stripe.js declarations for transpiled code.
22
+ - `web` contains dependency-free SSR helpers for Stripe script and pricing
23
+ table elements.
24
+ - `server` adapts the official Python Stripe SDK without depending on a web
25
+ framework.
26
+ - `testing` provides an in-memory mock suitable for application tests.
27
+ - `simulator` runs a stateful local Stripe-compatible HTTP service for complete
28
+ Checkout, webhook, subscription, and customer-portal scenarios.
29
+
30
+ Business concepts such as members, entitlements, and local subscription models
31
+ belong in an application or membership package rather than this integration.
32
+
33
+ Start the simulator with an application webhook destination:
34
+
35
+ ```console
36
+ uv run pyjs-stripe-simulator \
37
+ --webhook-url http://localhost:8000/stripe/webhook/
38
+ ```
39
+
40
+ The API uses `sk_test_local`, webhooks use `whsec_local`, and state is stored in
41
+ `.pyjs-stripe.sqlite3` by default. Point `StripeGateway(api_base=...)` at
42
+ `http://127.0.0.1:12111` so application code follows the same SDK path used with
43
+ Stripe.
44
+
45
+ Open <http://127.0.0.1:12111> for the PyJS operator dashboard. It can select
46
+ successful, retryable-decline, hard-decline, or authentication-required
47
+ behavior for each subscription, run renewals, retry open invoices, advance the
48
+ clock, replace payment methods, and inspect invoice retry state. Webhook tools
49
+ can switch between automatic, manual, and paused forwarding; deliver pending
50
+ events oldest- or newest-first; send duplicate events; and inject invalid or
51
+ stale signatures. Test-only JSON state, reset, and clock controls remain
52
+ available under `/_test/`.
53
+
54
+ The simulator uses three payment attempts before marking a retryable invoice
55
+ uncollectible and its subscription unpaid. See
56
+ [`stripe/SIMULATOR.md`](stripe/SIMULATOR.md) for its lifecycle contract and
57
+ deliberate limits. Product, price, amount, currency, and maximum payment
58
+ attempts can be changed with command-line options; run
59
+ `pyjs-stripe-simulator --help` for the complete list.
@@ -0,0 +1 @@
1
+ """Official integrations maintained by the PyJS project."""
@@ -0,0 +1,88 @@
1
+ Metadata-Version: 2.4
2
+ Name: pyjs-extras
3
+ Version: 0.4.0
4
+ Summary: Official third-party integrations for PyJS.
5
+ Author-email: Lex Berezhny <lex@damoti.com>
6
+ License-Expression: BSD-3-Clause
7
+ Project-URL: Homepage, https://github.com/pyjs/pyjs
8
+ Project-URL: Source, https://github.com/pyjs/pyjs
9
+ Classifier: Development Status :: 2 - Pre-Alpha
10
+ Classifier: Environment :: Web Environment
11
+ Classifier: Intended Audience :: Developers
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.14
17
+ Classifier: Topic :: Internet :: WWW/HTTP
18
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
19
+ Requires-Python: >=3.14
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: pyjs==0.4.0
23
+ Provides-Extra: stripe
24
+ Requires-Dist: stripe<15,>=14; extra == "stripe"
25
+ Provides-Extra: test
26
+ Requires-Dist: pytest>=9.0; extra == "test"
27
+ Requires-Dist: stripe<15,>=14; extra == "test"
28
+ Dynamic: license-file
29
+
30
+ # PyJS Extras
31
+
32
+ `pyjs-extras` contains official, optional integrations between PyJS and
33
+ third-party services. Install only the provider dependencies you need:
34
+
35
+ ```console
36
+ uv add "pyjs-extras[stripe]"
37
+ ```
38
+
39
+ When the matching PyJS version is already a direct dependency, this convenience
40
+ spelling is equivalent:
41
+
42
+ ```console
43
+ uv add "pyjs[stripe]"
44
+ ```
45
+
46
+ ## Stripe
47
+
48
+ `pyjs_extras.stripe` provides five deliberately separate surfaces:
49
+
50
+ - `browser` contains typed Stripe.js declarations for transpiled code.
51
+ - `web` contains dependency-free SSR helpers for Stripe script and pricing
52
+ table elements.
53
+ - `server` adapts the official Python Stripe SDK without depending on a web
54
+ framework.
55
+ - `testing` provides an in-memory mock suitable for application tests.
56
+ - `simulator` runs a stateful local Stripe-compatible HTTP service for complete
57
+ Checkout, webhook, subscription, and customer-portal scenarios.
58
+
59
+ Business concepts such as members, entitlements, and local subscription models
60
+ belong in an application or membership package rather than this integration.
61
+
62
+ Start the simulator with an application webhook destination:
63
+
64
+ ```console
65
+ uv run pyjs-stripe-simulator \
66
+ --webhook-url http://localhost:8000/stripe/webhook/
67
+ ```
68
+
69
+ The API uses `sk_test_local`, webhooks use `whsec_local`, and state is stored in
70
+ `.pyjs-stripe.sqlite3` by default. Point `StripeGateway(api_base=...)` at
71
+ `http://127.0.0.1:12111` so application code follows the same SDK path used with
72
+ Stripe.
73
+
74
+ Open <http://127.0.0.1:12111> for the PyJS operator dashboard. It can select
75
+ successful, retryable-decline, hard-decline, or authentication-required
76
+ behavior for each subscription, run renewals, retry open invoices, advance the
77
+ clock, replace payment methods, and inspect invoice retry state. Webhook tools
78
+ can switch between automatic, manual, and paused forwarding; deliver pending
79
+ events oldest- or newest-first; send duplicate events; and inject invalid or
80
+ stale signatures. Test-only JSON state, reset, and clock controls remain
81
+ available under `/_test/`.
82
+
83
+ The simulator uses three payment attempts before marking a retryable invoice
84
+ uncollectible and its subscription unpaid. See
85
+ [`stripe/SIMULATOR.md`](stripe/SIMULATOR.md) for its lifecycle contract and
86
+ deliberate limits. Product, price, amount, currency, and maximum payment
87
+ attempts can be changed with command-line options; run
88
+ `pyjs-stripe-simulator --help` for the complete list.
@@ -0,0 +1,31 @@
1
+ LICENSE
2
+ README.md
3
+ __init__.py
4
+ pyproject.toml
5
+ ./__init__.py
6
+ ./stripe/__init__.py
7
+ ./stripe/browser.py
8
+ ./stripe/server.py
9
+ ./stripe/simulator.py
10
+ ./stripe/simulator_delivery.py
11
+ ./stripe/simulator_store.py
12
+ ./stripe/simulator_types.py
13
+ ./stripe/simulator_ui.py
14
+ ./stripe/testing.py
15
+ ./stripe/web.py
16
+ pyjs_extras.egg-info/PKG-INFO
17
+ pyjs_extras.egg-info/SOURCES.txt
18
+ pyjs_extras.egg-info/dependency_links.txt
19
+ pyjs_extras.egg-info/entry_points.txt
20
+ pyjs_extras.egg-info/requires.txt
21
+ pyjs_extras.egg-info/top_level.txt
22
+ stripe/__init__.py
23
+ stripe/browser.py
24
+ stripe/server.py
25
+ stripe/simulator.py
26
+ stripe/simulator_delivery.py
27
+ stripe/simulator_store.py
28
+ stripe/simulator_types.py
29
+ stripe/simulator_ui.py
30
+ stripe/testing.py
31
+ stripe/web.py
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ pyjs-stripe-simulator = pyjs_extras.stripe.simulator:main
@@ -0,0 +1,8 @@
1
+ pyjs==0.4.0
2
+
3
+ [stripe]
4
+ stripe<15,>=14
5
+
6
+ [test]
7
+ pytest>=9.0
8
+ stripe<15,>=14
@@ -0,0 +1 @@
1
+ pyjs_extras
@@ -0,0 +1,64 @@
1
+ [build-system]
2
+ requires = ["setuptools>=82.0.1"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "pyjs-extras"
7
+ version = "0.4.0"
8
+ requires-python = ">=3.14"
9
+ authors = [
10
+ {name = "Lex Berezhny", email = "lex@damoti.com"},
11
+ ]
12
+ description = "Official third-party integrations for PyJS."
13
+ readme = "README.md"
14
+ license = "BSD-3-Clause"
15
+ license-files = ["LICENSE"]
16
+ dependencies = [
17
+ "pyjs==0.4.0",
18
+ ]
19
+ classifiers = [
20
+ "Development Status :: 2 - Pre-Alpha",
21
+ "Environment :: Web Environment",
22
+ "Intended Audience :: Developers",
23
+ "Operating System :: OS Independent",
24
+ "Programming Language :: Python",
25
+ "Programming Language :: Python :: 3",
26
+ "Programming Language :: Python :: 3 :: Only",
27
+ "Programming Language :: Python :: 3.14",
28
+ "Topic :: Internet :: WWW/HTTP",
29
+ "Topic :: Software Development :: Libraries :: Python Modules",
30
+ ]
31
+
32
+ [project.urls]
33
+ Homepage = "https://github.com/pyjs/pyjs"
34
+ Source = "https://github.com/pyjs/pyjs"
35
+
36
+ [project.optional-dependencies]
37
+ stripe = ["stripe>=14,<15"]
38
+ test = ["pytest>=9.0", "stripe>=14,<15"]
39
+
40
+ [project.scripts]
41
+ pyjs-stripe-simulator = "pyjs_extras.stripe.simulator:main"
42
+
43
+ [tool.setuptools]
44
+ include-package-data = false
45
+ packages = [
46
+ "pyjs_extras",
47
+ "pyjs_extras.stripe",
48
+ ]
49
+
50
+ [tool.setuptools.package-dir]
51
+ "pyjs_extras" = "."
52
+
53
+ [tool.pytest.ini_options]
54
+ testpaths = ["stripe/tests"]
55
+
56
+ [tool.uv.sources]
57
+ pyjs = {workspace = true}
58
+
59
+ [tool.ruff]
60
+ target-version = "py314"
61
+ line-length = 90
62
+
63
+ [tool.ruff.lint]
64
+ extend-select = ["B", "I", "UP"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,15 @@
1
+ """Backend-neutral Stripe interfaces for PyJS applications."""
2
+
3
+ from .server import (
4
+ CheckoutRequest,
5
+ HostedSession,
6
+ StripeGateway,
7
+ WebhookEvent,
8
+ )
9
+
10
+ __all__ = [
11
+ "CheckoutRequest",
12
+ "HostedSession",
13
+ "StripeGateway",
14
+ "WebhookEvent",
15
+ ]
@@ -0,0 +1,193 @@
1
+ """Typed declarations for Stripe.js and its current payment widgets."""
2
+
3
+ from collections.abc import Awaitable, Callable
4
+ from typing import Final, Literal, NotRequired, TypedDict, overload
5
+
6
+ from pyjs import JS, js
7
+ from pyjs.web.dom import Element
8
+
9
+
10
+ class StripeConstructorOptions(TypedDict):
11
+ stripeAccount: NotRequired[str]
12
+ apiVersion: NotRequired[str]
13
+ locale: NotRequired[str]
14
+ betas: NotRequired[list[str]]
15
+
16
+
17
+ class ElementsOptions(TypedDict):
18
+ clientSecret: NotRequired[str]
19
+ mode: NotRequired[Literal["payment", "setup", "subscription"]]
20
+ amount: NotRequired[int]
21
+ currency: NotRequired[str]
22
+ locale: NotRequired[str]
23
+ appearance: NotRequired[object]
24
+
25
+
26
+ class ElementOptions(TypedDict):
27
+ mode: NotRequired[Literal["billing", "shipping"]]
28
+ layout: NotRequired[str]
29
+ defaultValues: NotRequired[object]
30
+ fields: NotRequired[object]
31
+ wallets: NotRequired[object]
32
+ terms: NotRequired[object]
33
+
34
+
35
+ class ConfirmParams(TypedDict):
36
+ return_url: NotRequired[str]
37
+ receipt_email: NotRequired[str]
38
+
39
+
40
+ class ConfirmPaymentOptions(TypedDict):
41
+ elements: NotRequired[StripeElements]
42
+ clientSecret: NotRequired[str]
43
+ confirmParams: NotRequired[ConfirmParams]
44
+ redirect: NotRequired[Literal["always", "if_required"]]
45
+
46
+
47
+ class EmbeddedCheckoutOptions(TypedDict):
48
+ clientSecret: NotRequired[str]
49
+ fetchClientSecret: NotRequired[Callable[[], Awaitable[str]]]
50
+ onComplete: NotRequired[Callable[[], None]]
51
+
52
+
53
+ class StripeError(TypedDict):
54
+ type: str
55
+ message: str
56
+ code: NotRequired[str]
57
+ decline_code: NotRequired[str]
58
+
59
+
60
+ class PaymentResult(TypedDict):
61
+ error: NotRequired[StripeError]
62
+ paymentIntent: NotRequired[object]
63
+
64
+
65
+ class ElementChangeEvent(TypedDict):
66
+ elementType: str
67
+ empty: bool
68
+ complete: bool
69
+ error: NotRequired[StripeError]
70
+
71
+
72
+ ElementType = Literal[
73
+ "address",
74
+ "expressCheckout",
75
+ "linkAuthentication",
76
+ "payment",
77
+ "paymentMethodMessaging",
78
+ ]
79
+
80
+
81
+ @js.native
82
+ class StripeElement:
83
+ def mount(self, target: str | Element) -> None: ...
84
+
85
+ def unmount(self) -> None: ...
86
+
87
+ def destroy(self) -> None: ...
88
+
89
+ def focus(self) -> None: ...
90
+
91
+ def blur(self) -> None: ...
92
+
93
+ def clear(self) -> None: ...
94
+
95
+ def on(
96
+ self,
97
+ event_type: Literal["change", "ready", "focus", "blur", "escape"],
98
+ handler: Callable[[ElementChangeEvent], None],
99
+ ) -> None: ...
100
+
101
+
102
+ @js.native
103
+ class PaymentElement(StripeElement): ...
104
+
105
+
106
+ @js.native
107
+ class AddressElement(StripeElement): ...
108
+
109
+
110
+ @js.native
111
+ class ExpressCheckoutElement(StripeElement): ...
112
+
113
+
114
+ @js.native
115
+ class LinkAuthenticationElement(StripeElement): ...
116
+
117
+
118
+ @js.native
119
+ class StripeElements:
120
+ @overload
121
+ def create(
122
+ self,
123
+ element_type: Literal["payment"],
124
+ options: ElementOptions,
125
+ ) -> PaymentElement: ...
126
+
127
+ @overload
128
+ def create(
129
+ self,
130
+ element_type: Literal["address"],
131
+ options: ElementOptions,
132
+ ) -> AddressElement: ...
133
+
134
+ @overload
135
+ def create(
136
+ self,
137
+ element_type: Literal["expressCheckout"],
138
+ options: ElementOptions,
139
+ ) -> ExpressCheckoutElement: ...
140
+
141
+ @overload
142
+ def create(
143
+ self,
144
+ element_type: Literal["linkAuthentication"],
145
+ options: ElementOptions,
146
+ ) -> LinkAuthenticationElement: ...
147
+
148
+ def create(
149
+ self,
150
+ element_type: ElementType,
151
+ options: ElementOptions,
152
+ ) -> StripeElement: ...
153
+
154
+ async def update(self, options: ElementsOptions) -> None: ...
155
+
156
+ async def submit(self) -> object: ...
157
+
158
+ async def fetchUpdates(self) -> object: ...
159
+
160
+
161
+ @js.native
162
+ class EmbeddedCheckout:
163
+ def mount(self, target: str | Element) -> None: ...
164
+
165
+ def unmount(self) -> None: ...
166
+
167
+ def destroy(self) -> None: ...
168
+
169
+
170
+ @js.native
171
+ class StripeClient:
172
+ def elements(self, options: ElementsOptions) -> StripeElements: ...
173
+
174
+ async def confirmPayment(
175
+ self,
176
+ options: ConfirmPaymentOptions,
177
+ ) -> PaymentResult: ...
178
+
179
+ async def initEmbeddedCheckout(
180
+ self,
181
+ options: EmbeddedCheckoutOptions,
182
+ ) -> EmbeddedCheckout: ...
183
+
184
+
185
+ @js.native
186
+ def Stripe(
187
+ publishable_key: str,
188
+ options: StripeConstructorOptions | None = None,
189
+ ) -> StripeClient: ...
190
+
191
+
192
+ STRIPE_JS_URL: Final[JS[str]] = "https://js.stripe.com/v3/"
193
+ PRICING_TABLE_JS_URL: Final[JS[str]] = "https://js.stripe.com/v3/pricing-table.js"