billkit-eu 0.1.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.
- billkit_eu-0.1.0/.github/workflows/ci.yml +34 -0
- billkit_eu-0.1.0/.github/workflows/publish.yml +37 -0
- billkit_eu-0.1.0/CHANGELOG.md +58 -0
- billkit_eu-0.1.0/CONTRIBUTING.md +20 -0
- billkit_eu-0.1.0/LICENSE +201 -0
- billkit_eu-0.1.0/PKG-INFO +204 -0
- billkit_eu-0.1.0/README.md +176 -0
- billkit_eu-0.1.0/integration/scenarios.json +55 -0
- billkit_eu-0.1.0/pyproject.toml +77 -0
- billkit_eu-0.1.0/src/billkit/__init__.py +104 -0
- billkit_eu-0.1.0/src/billkit/_client.py +197 -0
- billkit_eu-0.1.0/src/billkit/_errors.py +181 -0
- billkit_eu-0.1.0/src/billkit/_logging.py +60 -0
- billkit_eu-0.1.0/src/billkit/_pagination.py +84 -0
- billkit_eu-0.1.0/src/billkit/_retry.py +74 -0
- billkit_eu-0.1.0/src/billkit/_transport.py +376 -0
- billkit_eu-0.1.0/src/billkit/_version.py +1 -0
- billkit_eu-0.1.0/src/billkit/_webhooks.py +123 -0
- billkit_eu-0.1.0/src/billkit/py.typed +0 -0
- billkit_eu-0.1.0/src/billkit/resources.py +2510 -0
- billkit_eu-0.1.0/tests/__init__.py +0 -0
- billkit_eu-0.1.0/tests/conftest.py +83 -0
- billkit_eu-0.1.0/tests/integration/__init__.py +0 -0
- billkit_eu-0.1.0/tests/integration/conftest.py +167 -0
- billkit_eu-0.1.0/tests/integration/test_integration.py +461 -0
- billkit_eu-0.1.0/tests/test_errors.py +146 -0
- billkit_eu-0.1.0/tests/test_happy_path.py +158 -0
- billkit_eu-0.1.0/tests/test_logging.py +166 -0
- billkit_eu-0.1.0/tests/test_new_resources.py +594 -0
- billkit_eu-0.1.0/tests/test_pagination_and_extras.py +174 -0
- billkit_eu-0.1.0/tests/test_retry.py +118 -0
- billkit_eu-0.1.0/tests/test_version.py +32 -0
- billkit_eu-0.1.0/tests/test_webhooks.py +158 -0
- billkit_eu-0.1.0/uv.lock +410 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
# Unit tests only. The integration suite is gated on
|
|
4
|
+
# BILLKIT_INTEGRATION_BASE_URL and skips itself here: it needs a live BillKit
|
|
5
|
+
# API, which is exercised in the private platform repo before a release is cut.
|
|
6
|
+
on:
|
|
7
|
+
push:
|
|
8
|
+
branches: [main]
|
|
9
|
+
pull_request:
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
test:
|
|
13
|
+
name: Python ${{ matrix.python }}
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
strategy:
|
|
16
|
+
fail-fast: false
|
|
17
|
+
matrix:
|
|
18
|
+
python: ['3.11', '3.12', '3.13']
|
|
19
|
+
steps:
|
|
20
|
+
- uses: actions/checkout@v7
|
|
21
|
+
- name: Install uv
|
|
22
|
+
uses: astral-sh/setup-uv@v9.0.0
|
|
23
|
+
with:
|
|
24
|
+
enable-cache: true
|
|
25
|
+
- name: Set up Python ${{ matrix.python }}
|
|
26
|
+
run: uv python install ${{ matrix.python }}
|
|
27
|
+
- name: Sync deps
|
|
28
|
+
run: uv sync --all-extras --dev
|
|
29
|
+
- name: Ruff
|
|
30
|
+
run: uv run ruff check .
|
|
31
|
+
- name: Mypy
|
|
32
|
+
run: uv run mypy src
|
|
33
|
+
- name: Pytest
|
|
34
|
+
run: uv run pytest -q
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
# Triggered by pushing a tag of the form ``vX.Y.Z``.
|
|
4
|
+
# The tag's version must match ``project.version`` in ``pyproject.toml``.
|
|
5
|
+
#
|
|
6
|
+
# The distribution is ``billkit-eu``; the import name is ``billkit``.
|
|
7
|
+
on:
|
|
8
|
+
push:
|
|
9
|
+
tags:
|
|
10
|
+
- 'v*'
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
publish:
|
|
14
|
+
name: Build + publish
|
|
15
|
+
runs-on: ubuntu-latest
|
|
16
|
+
permissions:
|
|
17
|
+
# PyPI trusted publishing (OIDC). Configure the ``billkit-eu`` project
|
|
18
|
+
# on PyPI to trust this workflow in this repository first.
|
|
19
|
+
id-token: write
|
|
20
|
+
steps:
|
|
21
|
+
- uses: actions/checkout@v7
|
|
22
|
+
- name: Install uv
|
|
23
|
+
uses: astral-sh/setup-uv@v9.0.0
|
|
24
|
+
- name: Verify tag matches pyproject.toml
|
|
25
|
+
run: |
|
|
26
|
+
TAG_VERSION="${GITHUB_REF_NAME#v}"
|
|
27
|
+
PKG_VERSION="$(uv run python -c 'import tomllib,pathlib; print(tomllib.loads(pathlib.Path("pyproject.toml").read_text())["project"]["version"])')"
|
|
28
|
+
if [ "$TAG_VERSION" != "$PKG_VERSION" ]; then
|
|
29
|
+
echo "::error::Tag ($TAG_VERSION) does not match pyproject.toml ($PKG_VERSION)."
|
|
30
|
+
exit 1
|
|
31
|
+
fi
|
|
32
|
+
- name: Test
|
|
33
|
+
run: uv run pytest -q
|
|
34
|
+
- name: Build
|
|
35
|
+
run: uv build
|
|
36
|
+
- name: Publish
|
|
37
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to the BillKit Python SDK will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
Versioning is independent of the Node SDK; the two ship on their own cadence,
|
|
9
|
+
so the numbers will diverge after this first release.
|
|
10
|
+
|
|
11
|
+
Published to PyPI as `billkit-eu`; the import name is `billkit`.
|
|
12
|
+
|
|
13
|
+
## [Unreleased]
|
|
14
|
+
|
|
15
|
+
## [0.1.0]
|
|
16
|
+
|
|
17
|
+
First public release.
|
|
18
|
+
|
|
19
|
+
### Added
|
|
20
|
+
- Sync (`BillKit`) and async (`AsyncBillKit`) clients over `httpx`.
|
|
21
|
+
- Full resource coverage: Customers, Products, Prices, CheckoutSessions,
|
|
22
|
+
Subscriptions, Refunds, WebhookEndpoints, Coupons, TaxRates, Invoices,
|
|
23
|
+
AuditLogs, Payments, Events, Tenant, BillingPortalSessions.
|
|
24
|
+
- Cursor pagination with `.list()` and `.iter()` helpers.
|
|
25
|
+
- Typed exception hierarchy (`APIConnectionError`, `AuthenticationError`,
|
|
26
|
+
`PermissionError`, `ResourceMissingError`, `InvalidRequestError`,
|
|
27
|
+
`ConflictError`, `RateLimitError`, `ServerError`) matching the BillKit
|
|
28
|
+
error envelope (`code`, `reason`, `message`, `param`).
|
|
29
|
+
- Automatic idempotency-key generation on every mutating call; overridable
|
|
30
|
+
via `idempotency_key=...` kwarg.
|
|
31
|
+
- Retry policy: 4 attempts, jittered exponential backoff (0.5→1→2→4s,
|
|
32
|
+
capped at 8s), retries network errors + 5xx (with idempotency) and 429
|
|
33
|
+
(respecting `Retry-After`).
|
|
34
|
+
- Configurable timeout (default 30s).
|
|
35
|
+
- `WebhookSignature.verify(payload, signature_header, secret)` for
|
|
36
|
+
verifying `BillKit-Signature` webhooks (HMAC-SHA256 with 5-min replay
|
|
37
|
+
protection). Multiple `v1` signatures in one header are accepted and pass if
|
|
38
|
+
any matches, which is what keeps inbound webhooks verifying through a
|
|
39
|
+
signing-secret rotation.
|
|
40
|
+
- **Opt-in logging.** The SDK emits its request/retry lifecycle to a single
|
|
41
|
+
`logging.getLogger("billkit")` with a `NullHandler` attached, the standard
|
|
42
|
+
library-author pattern. It stays silent until *your* application raises the
|
|
43
|
+
level, and it never calls `basicConfig`, never sets a level, and never adds a
|
|
44
|
+
handler to a logger it doesn't own.
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
logging.getLogger("billkit").setLevel(logging.DEBUG)
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
DEBUG gets one line per HTTP attempt and one per response (status, elapsed ms,
|
|
51
|
+
`X-Request-Id`); WARNING gets one line per retry. The logger is exported as
|
|
52
|
+
`billkit.logger`.
|
|
53
|
+
|
|
54
|
+
API keys, request/response bodies and query strings are never logged, and the
|
|
55
|
+
final failure is raised rather than logged so you never get a duplicate entry.
|
|
56
|
+
|
|
57
|
+
[Unreleased]: https://github.com/billkit-eu/billkit-python/compare/v0.1.0...HEAD
|
|
58
|
+
[0.1.0]: https://github.com/billkit-eu/billkit-python/releases/tag/v0.1.0
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
This repository is a **read-only mirror**. It is published from the BillKit monorepo, and
|
|
4
|
+
anything pushed here directly is overwritten by the next release.
|
|
5
|
+
|
|
6
|
+
Bug reports and feature requests are welcome as issues. For a code change, open an issue
|
|
7
|
+
first and we will apply it upstream with attribution.
|
|
8
|
+
|
|
9
|
+
## Running the tests
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
# whichever applies to this package
|
|
13
|
+
npm ci && npm test
|
|
14
|
+
uv sync && uv run pytest
|
|
15
|
+
composer install && composer test
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
The integration suite is gated on `BILLKIT_INTEGRATION_BASE_URL` and skips without it. It
|
|
19
|
+
drives a live BillKit API and runs upstream before each release; you are not missing a
|
|
20
|
+
step locally.
|
billkit_eu-0.1.0/LICENSE
ADDED
|
@@ -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 the acceptance of support, warranty, indemnity, or other
|
|
168
|
+
liability obligations and/or rights consistent with this License.
|
|
169
|
+
However, in accepting such obligations, You may act only on Your
|
|
170
|
+
own behalf and on Your sole responsibility, not on behalf of any
|
|
171
|
+
other Contributor, and only if You agree to indemnify, defend,
|
|
172
|
+
and hold each Contributor harmless for any liability incurred by,
|
|
173
|
+
or claims asserted against, such Contributor by reason of your
|
|
174
|
+
accepting any 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 2026 BillKit
|
|
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
|
|
201
|
+
permissions and limitations under the License.
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: billkit-eu
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Official Python SDK for BillKit: a Stripe-Billing-shape multi-tenant SaaS API on Mollie.
|
|
5
|
+
Project-URL: Homepage, https://billkit.eu
|
|
6
|
+
Project-URL: Documentation, https://docs.billkit.eu
|
|
7
|
+
Project-URL: Source, https://github.com/billkit-eu/billkit-python
|
|
8
|
+
Project-URL: Issues, https://github.com/billkit-eu/billkit-python/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/billkit-eu/billkit-python/blob/main/CHANGELOG.md
|
|
10
|
+
Author-email: BillKit <sdk@billkit.eu>
|
|
11
|
+
License-Expression: Apache-2.0
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Keywords: billing,billkit,eu,mollie,saas,stripe,subscriptions
|
|
14
|
+
Classifier: Development Status :: 4 - Beta
|
|
15
|
+
Classifier: Framework :: AsyncIO
|
|
16
|
+
Classifier: Intended Audience :: Developers
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Topic :: Office/Business :: Financial
|
|
23
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
24
|
+
Classifier: Typing :: Typed
|
|
25
|
+
Requires-Python: >=3.11
|
|
26
|
+
Requires-Dist: httpx>=0.28.0
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
# BillKit Python SDK
|
|
30
|
+
|
|
31
|
+
Async + sync client for [BillKit](https://billkit.eu), the Stripe-Billing-shape multi-tenant SaaS API on Mollie.
|
|
32
|
+
|
|
33
|
+
## Install
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
pip install billkit-eu
|
|
37
|
+
# or
|
|
38
|
+
uv add billkit
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Requires Python 3.11+.
|
|
42
|
+
|
|
43
|
+
## Quick start
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
from billkit import BillKit
|
|
47
|
+
|
|
48
|
+
client = BillKit(api_key="sk_test_...")
|
|
49
|
+
|
|
50
|
+
customer = client.customers.create(email="ada@example.com", name="Ada Lovelace")
|
|
51
|
+
product = client.products.create(
|
|
52
|
+
name="Pro",
|
|
53
|
+
description="Hosted billing for SaaS",
|
|
54
|
+
marketing_features=["Checkout", "Subscriptions"],
|
|
55
|
+
)
|
|
56
|
+
price = client.prices.create(
|
|
57
|
+
product_id=product["id"],
|
|
58
|
+
amount_cents=999,
|
|
59
|
+
currency="EUR",
|
|
60
|
+
interval="month",
|
|
61
|
+
trial_days=14,
|
|
62
|
+
payment_methods=["creditcard", "directdebit"],
|
|
63
|
+
)
|
|
64
|
+
session = client.checkout_sessions.create(
|
|
65
|
+
customer_id=customer["id"],
|
|
66
|
+
price_id=price["id"],
|
|
67
|
+
success_url="https://app.example.com/success",
|
|
68
|
+
cancel_url="https://app.example.com/cancel",
|
|
69
|
+
)
|
|
70
|
+
print(session["url"]) # redirect the user here
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## One-shot (mandate-less) payments
|
|
74
|
+
|
|
75
|
+
A one-shot is a single charge with no subscription, mandate or renewals: the Stripe PaymentIntent shape, mapped onto Mollie. Create it, redirect to `redirect_url`, and settle terminal state via the `one_shot_payment.succeeded` / `.failed` webhook events.
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
payment = client.one_shot_payments.create(
|
|
79
|
+
customer_id=customer["id"],
|
|
80
|
+
amount_cents=2500,
|
|
81
|
+
currency="EUR",
|
|
82
|
+
method="ideal",
|
|
83
|
+
success_url="https://shop.example.com/thanks",
|
|
84
|
+
refund_window_days=14, # optional; 0 disables refunds, default is 30
|
|
85
|
+
)
|
|
86
|
+
print(payment["redirect_url"]) # redirect the payer here
|
|
87
|
+
|
|
88
|
+
# Later, refund it within its window (omit amount_cents for a full refund):
|
|
89
|
+
client.refunds.create(one_shot_payment_id=payment["id"])
|
|
90
|
+
# ...or refund part of it. A charge can carry several partials:
|
|
91
|
+
client.refunds.create(one_shot_payment_id=payment["id"], amount_cents=500)
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Async
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
from billkit import AsyncBillKit
|
|
98
|
+
|
|
99
|
+
async with AsyncBillKit(api_key="sk_test_...") as client:
|
|
100
|
+
customer = await client.customers.create(email="ada@example.com")
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Configuration
|
|
104
|
+
|
|
105
|
+
```python
|
|
106
|
+
from billkit import BillKit, RetryPolicy
|
|
107
|
+
|
|
108
|
+
client = BillKit(
|
|
109
|
+
api_key="sk_test_...", # or set BILLKIT_API_KEY
|
|
110
|
+
base_url="https://api.billkit.eu", # override for self-hosted
|
|
111
|
+
timeout=30.0, # seconds, or pass httpx.Timeout
|
|
112
|
+
retry_policy=RetryPolicy(
|
|
113
|
+
max_attempts=5,
|
|
114
|
+
max_retry_after_seconds=10.0, # cap 429 Retry-After sleeps
|
|
115
|
+
),
|
|
116
|
+
)
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
The SDK auto-generates an `Idempotency-Key` for every mutating call, so 5xx and short `Retry-After` 429 retries are safe: the server replays the original response when an earlier attempt completed. Pass `idempotency_key=` to coalesce retries across process restarts.
|
|
120
|
+
|
|
121
|
+
## Errors
|
|
122
|
+
|
|
123
|
+
```python
|
|
124
|
+
from billkit import BillKit, ResourceMissingError, RateLimitError, BillKitError
|
|
125
|
+
|
|
126
|
+
client = BillKit(api_key="sk_test_...")
|
|
127
|
+
try:
|
|
128
|
+
customer = client.customers.retrieve("cus_doesnt_exist")
|
|
129
|
+
except ResourceMissingError:
|
|
130
|
+
print("Customer is gone")
|
|
131
|
+
except RateLimitError as exc:
|
|
132
|
+
print(f"Rate limited; retry in {exc.retry_after}s")
|
|
133
|
+
except BillKitError as exc:
|
|
134
|
+
print(f"BillKit error {exc.status_code}: {exc.message}")
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
All errors inherit from `BillKitError`. Subclasses: `APIConnectionError`, `APIError`, `ServerError`, `AuthenticationError`, `PermissionError`, `ResourceMissingError`, `InvalidRequestError`, `ConflictError`, `RateLimitError`.
|
|
138
|
+
|
|
139
|
+
## Logging
|
|
140
|
+
|
|
141
|
+
The SDK is **silent by default**. It owns one logger, `logging.getLogger("billkit")`, with a `NullHandler` attached, and it never calls `basicConfig`, never sets a level, and never adds a handler to a logger it doesn't own. Your logging config is yours.
|
|
142
|
+
|
|
143
|
+
Turn it on from your application:
|
|
144
|
+
|
|
145
|
+
```python
|
|
146
|
+
import logging
|
|
147
|
+
|
|
148
|
+
logging.basicConfig()
|
|
149
|
+
logging.getLogger("billkit").setLevel(logging.DEBUG)
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
```
|
|
153
|
+
DEBUG:billkit:BillKit request POST https://api.billkit.eu/v1/customers (attempt 1/3)
|
|
154
|
+
DEBUG:billkit:BillKit response POST https://api.billkit.eu/v1/customers -> 503 in 84ms (request_id=req_9f2a)
|
|
155
|
+
WARNING:billkit:BillKit retrying POST https://api.billkit.eu/v1/customers after HTTP 503 (attempt 1) in 500ms
|
|
156
|
+
DEBUG:billkit:BillKit response POST https://api.billkit.eu/v1/customers -> 200 in 91ms (request_id=req_9f2b)
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
- **DEBUG**: one line per attempt, one per response (status, elapsed ms, `X-Request-Id`; quote that id to support).
|
|
160
|
+
- **WARNING**: one line per retry, with the reason and the delay before the next attempt.
|
|
161
|
+
|
|
162
|
+
**Never logged:** your API key or the `Authorization` header; request and response **bodies** (they carry customer PII); the **query string** (list filters carry values like `email=`); only the path is logged. The final failure isn't logged either: it's raised as a typed `BillKitError` carrying the status, request id and retry-after, and logging it here too would hand you a duplicate you can't suppress.
|
|
163
|
+
|
|
164
|
+
The logger object is exported if you'd rather wire it up directly:
|
|
165
|
+
|
|
166
|
+
```python
|
|
167
|
+
from billkit import logger
|
|
168
|
+
|
|
169
|
+
logger.addHandler(my_handler)
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
## Webhook verification
|
|
173
|
+
|
|
174
|
+
```python
|
|
175
|
+
from billkit import WebhookSignature, WebhookVerificationError
|
|
176
|
+
|
|
177
|
+
# In your FastAPI / Flask / Django handler:
|
|
178
|
+
try:
|
|
179
|
+
event = WebhookSignature.verify(
|
|
180
|
+
payload=request.body,
|
|
181
|
+
signature_header=request.headers.get("BillKit-Signature"),
|
|
182
|
+
secret=os.environ["BILLKIT_WEBHOOK_SECRET"],
|
|
183
|
+
)
|
|
184
|
+
except WebhookVerificationError:
|
|
185
|
+
return Response(status_code=400)
|
|
186
|
+
|
|
187
|
+
if event["type"] == "subscription.created":
|
|
188
|
+
handle_new_subscription(event["data"])
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
The verifier enforces a 5-minute timestamp tolerance (replay protection) and constant-time HMAC compare. Pass `tolerance_seconds=` to customise.
|
|
192
|
+
|
|
193
|
+
## Development
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
uv sync --all-extras --dev
|
|
197
|
+
uv run pytest
|
|
198
|
+
uv run ruff check
|
|
199
|
+
uv run mypy src
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
## License
|
|
203
|
+
|
|
204
|
+
Proprietary.
|