ScanUpload API Client - Python
Get a bearer token from ScanUpload using a client ID + secret, then download the files captured for a session. Two API methods, zero web-framework dependencies.
Quickstart
-
Get your client credentials from the ScanUpload Dashboard:
- Sign in to app.scanupload.net.
- On the dashboard, enter your company name and website URL, then click Save.
- Open the client credentials section and click Generate to mint a client ID + secret.
- The dashboard will also show your
KEYCLOAK_SERVER_URLandKEYCLOAK_REALM— copy them too.
-
Install the client:
pip install scan-upload-api-client
-
Configure it (env vars or a
.envfile):KEYCLOAK_SERVER_URL=https://identity.scanupload.net/ KEYCLOAK_REALM=scanupload-hub KEYCLOAK_CLIENT_ID=<paste from the dashboard> KEYCLOAK_CLIENT_SECRET=<paste from the dashboard> HUB_BASE_URL=https://hub.scanupload.net
-
Download a session in 7 lines:
import asyncio from scan_upload_api_client import ( KeycloakClient, ScanUploadApiClient, ScanUploadOptions, TokenProvider, ) async def main(): opts = ScanUploadOptions() # reads the KEYCLOAK_* env vars above async with KeycloakClient(opts) as kc: tp = TokenProvider(kc, opts) api = ScanUploadApiClient("https://hub.scanupload.net", tp) async def save(name, content): open(f"downloads/{name}", "wb").write(content) await api.download_async("your-session-id", save) asyncio.run(main())
That's the whole thing. See
examples/quickstart.py for the runnable
version.
Never commit
KEYCLOAK_CLIENT_SECRETto source control. Use a secrets manager or your CI/CD provider's secret store.
Configuration reference
ScanUploadOptions reads from environment variables (or .env).
Booleans default to False, strings default to "", durations default
to timedelta(seconds=60), unless noted:
| Field | Env var | Purpose |
|---|---|---|
keycloak_server_url |
KEYCLOAK_SERVER_URL |
Base URL of your Keycloak server |
keycloak_realm |
KEYCLOAK_REALM |
Realm that hosts this client |
keycloak_client_id |
KEYCLOAK_CLIENT_ID |
Client ID for the credentials grant |
keycloak_client_secret |
KEYCLOAK_CLIENT_SECRET |
Client secret for the credentials grant |
keycloak_scope |
KEYCLOAK_SCOPE |
Optional OAuth2 scope (openid profile email scanupload.hub works for the hosted SaaS) |
keycloak_early_refresh_seconds |
n/a | Refresh margin before token expiry (default 120) |
To pass values directly instead of from env vars:
options = ScanUploadOptions(
keycloak_server_url="https://identity.scanupload.net/",
keycloak_realm="scanupload-hub",
keycloak_client_id="...",
keycloak_client_secret="...",
)
Streaming entries straight to disk
If you don't want to buffer each zip entry in memory before writing it,
swap download_async for download_async_streaming. The callback
receives a ZipEntryStream you can drain chunk by chunk:
from scan_upload_api_client import ZipEntryStream
async def stream_to_disk(name: str, entry: ZipEntryStream) -> None:
with open(f"downloads/{name}", "wb") as fh:
async for chunk in entry.read_chunks(): # 64 KiB by default
fh.write(chunk)
await api.download_async_streaming("your-session-id", stream_to_disk)
HTTP integration test (optional)
examples/integration_test.py is a
small FastAPI app that hosts the client behind HTTP, mirroring the .NET
ScanUpload.Api.Client.Test sample. It exposes /token,
/cached-token, /download-file/{session_id}, /health, and /
on http(s)://localhost:7021. Pre-baked VS Code REST Client scenarios
live in
examples/ScanUpload.Api.Client.Test.http.
pip install -e .[integration-test]
python examples/integration_test.py
API at a glance
| Symbol | Purpose |
|---|---|
ScanUploadOptions |
Configuration container |
KeycloakClient |
Performs the OAuth2 client-credentials grant |
TokenProvider |
Caches tokens and refreshes them on demand |
ScanUploadApiClient |
Downloads a session's files |
download_async(id, cb) |
cb receives (name, bytes) per entry |
download_async_streaming(id, cb) |
cb receives (name, ZipEntryStream) per entry |
ZipEntryStream |
Async-friendly view over a zip entry body |
TokenResponse |
OAuth2 token response model |
KeycloakException |
Raised for any Keycloak/auth failure |
Running tests
pip install -e .[test]
pytest
Compatibility
- Python 3.11+
- Fully async (
httpx.AsyncClient) - Thread-safe token caching
- Zero web-framework dependencies — works in FastAPI, Starlette, Django async views, Flask, plain asyncio, etc.
License
See the repository license file for terms.
Metadata
Release files for scan-upload-api-client 1.0.3
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 |
|---|---|---|---|---|
| scan_upload_api_client-1.0.3.tar.gz | 18.4 kB | Without provenance | Details for scan_upload_api_client-1.0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| scan_upload_api_client-1.0.3-py3-none-any.whl | Python 3 | none | any | Details for scan_upload_api_client-1.0.3-py3-none-any.whl |
Total release size: 30.1 kB
Release files / scan_upload_api_client-1.0.3.tar.gz
| Download URL | scan_upload_api_client-1.0.3.tar.gz |
|---|---|
| Size | 18.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
144d6ec11d563cfeef67d82a59430f4caa364b5eb7a4a13ccd3b63491c8a862e
|
|
BLAKE2b-256 checksum How to use checksums |
25ea1f6df97e9710e9a25547a65723c775aae67333a9a80f017a921e9356c15b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.15
|
Release files / scan_upload_api_client-1.0.3-py3-none-any.whl
| Download URL | scan_upload_api_client-1.0.3-py3-none-any.whl |
|---|---|
| Size | 11.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0173b7ac0e18a5a8cad78482cb1845218310293fb8c7e2770539ee0676b91095
|
|
BLAKE2b-256 checksum How to use checksums |
61fc5626cdfd8caefc7d8b657d860764ac0c6a62f9bd4a8edd04c5df14bc5e7a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.15
|
Security for scan-upload-api-client 1.0.3
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.