Sponsorkit for Python

Install and use the sponsorkit package in command-line tools, desktop apps, services and async code on Python 3.10+.

On this page

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:

Terminal
python -m pip install sponsorkit

To use an unreleased change, build from source installs straight from the Git repository.

Check the install without signing in or touching the network:

Terminal
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 1

Sponsorkit 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#

my_cli.py
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:

NameWhat it is
SponsorkitThe client: reads contributions, signs in, opens checkout, creates nags.
ContributionResult, Contribution, CheckoutResult, Money, Supporter, …Frozen dataclasses for results.
SponsorkitError, ErrorCodeThe one exception type and its codes.
verify_session, averify_sessionBackend verification (also in sponsorkit.server).
Storage, FileStorage, MemoryStorageWhere the client keeps its state.
MockPreset, MockData, reset_process_stateTesting helpers.

In this section#

PageWhat it covers
QuickstartA complete CLI, and the same flow with asyncio.
ConfigurationEvery constructor option with its default, and the environment variables.
Sign-inLoopback and paste-back sign-in, adding identities, timeouts and cancellation.
Contributionsget_financial_contribution(), the result, its helpers and caching.
Checkoutopen_checkout() and checkout_url().
NagAsking for support every N runs or N days.
TestingMock mode, in-memory storage, a fake clock and a fake API with httpx.MockTransport.
Backend verificationChecking a supporter on your server with verify_session().
Errors and cancellationSponsorkitError, its codes, retry_after, and cancelling with events.
Platform notesAsync 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.