Python API reference

Every public class, function, type alias and constant of the sponsorkit package 1.0.0.

On this page

Reference for the sponsorkit Python package, version 1.0.0, generated from its source code and docstrings. For explanations and complete examples start with the Python guide; the concepts behind every SDK are in Concepts.

Terminal
python -m pip install sponsorkit

Import everything from the top-level package: from sponsorkit import Sponsorkit. The backend helpers live in sponsorkit.server and are re-exported too. Every blocking method of the client has an a-prefixed async variant (sign_in() and asign_in()).

Client#

NameKindSummary
SponsorkitclassReports what the current user contributed to your accounts, and sends them to contribute.
NagclassA named nag created by Sponsorkit.nag().
SignInMethodtype aliasHow native sign-in delivers the code.
CancelEventtype aliasThe cancellation primitive for sync calls: set the event to cancel.

Results#

NameKindSummary
ContributionResultclassWhat the current user has contributed to the configured targets.
ContributionclassA sponsorship (GitHub) or order (Open Collective) to one of the targets.
CheckoutResultclassThe outcome of Sponsorkit.open_checkout().
MoneyclassAn amount in minor units (cents) and an uppercase ISO 4217 currency.
SponsorEntityclassWho pays: the signed-in user or an organization they belong to.
TierclassA provider tier.
SupporterclassThe signed-in supporter.
IdentityclassA provider account the supporter signed in with.
Statustype aliasOne of active, paused, cancelled, paid, refunded, disputed, failed, pending.
Frequencytype aliasOne of one_time, monthly, yearly.
Kindtype aliasOne of recurring, one_time.

Errors#

NameKindSummary
SponsorkitErrorexceptionAn error raised by Sponsorkit.
ErrorCodetype aliasEvery value SponsorkitError.code can take.

Backend verification#

NameKindSummary
verify_session()functionVerify a session token and return the supporter's live contributions.
averify_session()functionAsync variant of verify_session() (uses AsyncClient).
sponsorkit.server.TargetsArgtype aliasTargets as {"github": ..., "open_collective": ...}, a target param, or a list of target strings.

Targets#

NameKindSummary
TargetclassA normalized target (lowercased, trimmed account).
Providertype aliasA contribution provider.
targets_param()functionThe canonical target param: the canonical set joined with ,.
targets_hash()functionLowercase hex SHA-256 of the UTF-8 target param (used for storage keys).

Storage#

NameKindSummary
StorageprotocolA key/value store for the SDK's state.
FileStorageclassStores <key>.json files in a directory (the default storage).
MemoryStorageclassIn-memory storage: nothing touches the disk.
default_storage_dir()functionReturn the per-user config directory used when no storage_dir is given.

Testing#

NameKindSummary
MockPresettype aliasA mock preset name.
MockDataclassCustom mock data: the SDK reports a signed-in supporter with exactly these contributions.
MOCK_PRESET_NAMESconstantEvery mock preset name, in the order of the MockPreset literal.
reset_process_state()functionForget per-process memo state, as if the app had been restarted.

Helpers#

NameKindSummary
parse_duration()functionParse an ISO-8601 duration (P7D, PT12H, P1W…); a timedelta passes through.
__version__constantThe installed package version.

Other public names#

Exported by a public submodule (not by sponsorkit itself).

NameKindSummary
sponsorkit.targets.PROVIDERSconstantEvery supported provider.
sponsorkit.targets.canonical_targets()functionDeduplicate and sort a target set; at least one target, at most one per provider.
sponsorkit.targets.normalize_target()functionValidate and normalize one target.
sponsorkit.targets.parse_target()functionParse "github:octocat" into a Target.
sponsorkit.targets.targets_from_options()functionBuild a canonical target set from github= / open_collective= handles.
sponsorkit.targets.targets_from_param()functionParse a target param such as "github:x,open-collective:y".
sponsorkit.mock.mock_checkout_contribution()functionThe contribution open_checkout() simulates in mock mode.
sponsorkit.mock.mock_result()functionThe result mock mode returns for a canonical target set.
sponsorkit.pkce.base64url()functionBase64url without padding.
sponsorkit.pkce.code_challenge()functionbase64url(sha256(ascii(verifier))) without padding.
sponsorkit.pkce.generate_code_verifier()function32 random bytes, base64url-encoded: a 43-character code verifier.

Modules#

ModuleSummary
sponsorkitSponsorkit: build GitHub Sponsors and Open Collective contributions directly into your software.
sponsorkit.clientThe Sponsorkit client.
sponsorkit.modelsThe contribution result shape, identical in every Sponsorkit SDK.
sponsorkit.errorsThe single exception type raised by Sponsorkit.
sponsorkit.serverBackend verification: check a supporter's session token without any key.
sponsorkit.nagThe nag helper: decide when to show a gentle "please support" message.
sponsorkit.storageLocal storage.
sponsorkit.targetsTargets and target sets.
sponsorkit.mockMock mode.
sponsorkit.pkcePKCE helpers.