Sponsorkit for Python
Install and use the sponsorkit package in command-line tools, desktop apps, services and async code on Python 3.10+.
sponsorkit tells your Python program what the current user has contributed to your GitHub Sponsors and Open
Collective accounts, and sends them to contribute. It is made for software that one person runs on their own
machine: command-line tools, desktop apps, Jupyter extensions, editor plugins. It also has a helper that lets
a web backend check a supporter's session.
- Python 3.10 or later, on Linux, macOS and Windows.
- One runtime dependency: httpx.
- Fully typed (ships
py.typed), so mypy and Pyright check your calls. - A blocking API, plus an
a-prefixed async variant of every blocking method (asign_in,aget_financial_contribution, …) for asyncio code.
Install#
sponsorkit is on PyPI. Install it with your package manager:
python -m pip install sponsorkituv add sponsorkitpoetry add sponsorkitpdm add sponsorkitpipenv install sponsorkitAny build backend (Hatch, setuptools, Flit, PDM, Poetry 2) reads the standard [project] table:
[project]
dependencies = [
"sponsorkit>=0.2,<0.3",
]sponsorkit>=0.2,<0.3To use an unreleased change, build from source installs straight from the Git repository.
Check the install without signing in or touching the network:
SPONSORKIT_MOCK=active-monthly python -c "import sponsorkit as s; print(s.__version__, len(s.Sponsorkit(github='octocat').get_financial_contribution().active()))"
# 1.0.0 1Sponsorkit is a library: declare it as a dependency of your own tool instead of installing it with pipx.
When your users run pipx install your-tool or uv tool install your-tool, it comes along.
A first look#
from sponsorkit import Sponsorkit
sk = Sponsorkit(github="octocat", open_collective="my-collective", app_name="my-cli")
fc = sk.get_financial_contribution() # cached for an hour; never raises because of the network
if fc.active():
print("Thank you for supporting my-cli!")
elif fc.signed_in:
print(f"Enjoying my-cli? Support it: {sk.checkout_url(frequency='monthly')}")Replace octocat and my-collective with the accounts you receive contributions on; one of the two is
enough. The quickstart turns this into a complete tool with login, logout and sponsor
commands.
What you can import#
Everything is importable from the top-level package:
| Name | What it is |
|---|---|
Sponsorkit | The client: reads contributions, signs in, opens checkout, creates nags. |
ContributionResult, Contribution, CheckoutResult, Money, Supporter, … | Frozen dataclasses for results. |
SponsorkitError, ErrorCode | The one exception type and its codes. |
verify_session, averify_session | Backend verification (also in sponsorkit.server). |
Storage, FileStorage, MemoryStorage | Where the client keeps its state. |
MockPreset, MockData, reset_process_state | Testing helpers. |
In this section#
| Page | What it covers |
|---|---|
| Quickstart | A complete CLI, and the same flow with asyncio. |
| Configuration | Every constructor option with its default, and the environment variables. |
| Sign-in | Loopback and paste-back sign-in, adding identities, timeouts and cancellation. |
| Contributions | get_financial_contribution(), the result, its helpers and caching. |
| Checkout | open_checkout() and checkout_url(). |
| Nag | Asking for support every N runs or N days. |
| Testing | Mock mode, in-memory storage, a fake clock and a fake API with httpx.MockTransport. |
| Backend verification | Checking a supporter on your server with verify_session(). |
| Errors and cancellation | SponsorkitError, its codes, retry_after, and cancelling with events. |
| Platform notes | Async variants, threads, operating systems, storage locations, logging. |
The API reference lists every class, method, field and type alias, generated from the package's source and docstrings.