Requirements
You need to have an account in pingen and obtain oauth credentials for your desired grant type (usually client_credentials).
How to obtain these are described here: https://api.pingen.com/documentation#section/Authentication/How-to-obtain-a-Client-ID
Python 3.11+
Installation
You don't need this source code unless you want to modify the package. If you just want to use the package, just run:
pip install --upgrade pingen2sdk
Environments
We have two Environments available: Production and Staging (see https://api.pingen.com/documentation#section/Basics/Environments)
This SDK supports staging as well. When initiating the resource (see Usage), the optional 'staging' attribute should be set, as well as when creating an endpoint object.
Usage
The simplest way to integrate is using the client credentials grant (see https://api.pingen.com/documentation#section/Authentication/Which-grant-type-should-i-use)
Recommended: the Pingen client
Create a Pingen client once with your credentials and obtain resources from it.
The access token is fetched once, reused across all resources and refreshed
automatically before it expires, so you never pass a token or the staging flag
around:
import pingen2sdk
pingen = pingen2sdk.Pingen(
client_id="YOUR_CLIENT_ID",
client_secret="YOUR_SECRET",
use_staging=True,
scope="letter batch webhook organisation_read email ebill",
)
organisationList = pingen.organisations().get_collection()
organisation_id = organisationList.data["data"][0]["id"]
response = pingen.letters(organisation_id).upload_and_create(
"./letter.pdf",
"sdk.pdf",
"left",
False,
"fast",
"simplex",
"color",
)
letter_id = response.data["data"]["id"]
Manual token handling
You can also obtain a token yourself and pass it (as a string) to each resource. This still works and is fully supported:
import pingen2sdk
pingen2sdk.client_id = "YOUR_CLIENT_ID"
pingen2sdk.client_secret = "YOU_SECRET"
resp = pingen2sdk.OAuth.get_token(
use_staging=True,
grant_type="client_credentials",
scope="letter batch webhook organisation_read",
)
access_token = resp["access_token"]
organisationList = pingen2sdk.Organisations(access_token, True).get_collection()
organisation_id = organisationList.data["data"][0]["id"]
LettersEndpoint = pingen2sdk.Letters(organisation_id, access_token, True)
response = LettersEndpoint.upload_and_create(
"./letter.pdf",
"sdk.pdf",
"left",
False,
"fast",
"simplex",
"color",
)
letter_id = response.data["data"]["id"]
Tip: pass the
pingen2sdk.OAuthinstance (instead of a raw token string) to any resource constructor to get the same automatic token reuse and refresh without using thePingenclient.
Examples & Docs
Our API Docs are here: https://api.pingen.com/documentation
On the right-hand side of every endpoint you can see request samples for Python and other languages, which you can copy and paste into your application.
Bugreport & Contribution
If you find a bug, please either create a ticket in github, or initiate a pull request.
Versioning
We adhere to semantic (major.minor.patch) versioning (https://semver.org/). This means that:
- Patch (x.x.patch) versions fix bugs
- Minor (x.minor.x) versions introduce new, backwards compatible features or improve existing code.
- Major (major.x.x) versions introduce radical changes which are not backwards compatible.
In your automation or procedure you can always safely update patch & minor versions without the risk of your application failing.
Testing
Run all tests for a specific Python version (modify -e according to your Python target):
tox -e py312
Run the linter with:
tox -e lint
The library uses Black for code formatting. Code must be formatted with Black before PRs are submitted, otherwise CI will fail. Run the formatter with:
tox -e fmt
Integration tests
tests/integration contains an end-to-end suite that runs against the real
Pingen staging API (organisations, letters, batches, webhooks, emails,
e-bills and user endpoints). It is marked with the integration marker and is
therefore excluded from the normal test run – it never runs unless you ask
for it explicitly.
-
Copy the credentials template and fill in your staging OAuth credentials:
cp .env.example .env
Fill in
PINGEN2_CLIENT_IDandPINGEN2_CLIENT_SECRET. Optionally setPINGEN2_ORGANISATION_IDto run against a specific organisation (handy when your credentials have access to several); when left empty the first organisation returned by the API is used.(
.envis git-ignored. The values can also be supplied as real environment variables, e.g. in CI.) -
Run only the integration suite:
pytest -m integration tests/integration
If no credentials are configured, every integration test is skipped rather than
failing, so pytest -m integration is safe to run anywhere. The cancel / delete
/ update steps assert strictly against the real API and therefore need the
deliverable to reach the required state (they rely on the committed
test_simulate_cancellable.pdf document and short time.sleep waits).
Metadata
Release files for pingen2sdk 2.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pingen2sdk-2.3.1.tar.gz | 31.9 kB | Without provenance | Details for pingen2sdk-2.3.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pingen2sdk-2.3.1-py3-none-any.whl | Python 3 | none | any | Details for pingen2sdk-2.3.1-py3-none-any.whl |
Total release size: 53.6 kB
Release files / pingen2sdk-2.3.1.tar.gz
| Download URL | pingen2sdk-2.3.1.tar.gz |
|---|---|
| Size | 31.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0db5c013b1072fb4d235c87cda53ff29a4f885c0e57d03198936d59ad49955e7
|
|
BLAKE2b-256 checksum How to use checksums |
ddb9ec660e86e5739c7f84e8615fbf37dee10a068c13bb042575ff92012bd18a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / pingen2sdk-2.3.1-py3-none-any.whl
| Download URL | pingen2sdk-2.3.1-py3-none-any.whl |
|---|---|
| Size | 21.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0e759291fc3e51d0526fcc5926665b224dadf52a07d13b41ba91d62374800f58
|
|
BLAKE2b-256 checksum How to use checksums |
97604e93ecaa8020a8c87a051e89eb207bf5a3329367f3f029a6077f74e58b4e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Security for pingen2sdk 2.3.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.