Skip to main content

Slip2Sure Python

SDK for integrating with the Slip2Sure slip verification service. (Python)

For the full API documentation, see:

Install

pip install slip2sure

Requires Python 3.10 or newer; tested on 3.10 through 3.14. Ships type annotations (PEP 561), so type checkers pick them up with no stubs needed.

Example

Truemoney

import asyncio
from slip2sure import Slip2SureAPI

async def main():
    async with Slip2SureAPI("YOUR_API_KEY") as client:
        # You can use Flask or FastAPI to receive the body
        with open("FILE_PATH", "rb") as f:
            result = await client.scanTruemoneySlip(f.read())

        print(result.info.amount, result.info.paid_at)

asyncio.run(main())

Bank Slip

import asyncio
from slip2sure import Slip2SureAPI

async def main():
    async with Slip2SureAPI("YOUR_API_KEY") as client:
        result = await client.scanBankSlipByPayload("YOUR_QR_CODE")
        print(result.info.amount, result.info.sender.displayName)

asyncio.run(main())

The client holds one aiohttp session across calls, so keep a single instance alive rather than building one per request. Use it as an async context manager, or call await client.close() when you are done.

Endpoints

Every method is available in camelCase, matching earlier releases, and in snake_case for PEP 8 style. scanTruemoneySlip and scan_truemoney_slip are the same function.

Slip verification — needs the Application API Key

Method API
scanTruemoneySlip(file) POST /truemoney/v2/verify
scanTruemoneySlipV1(file) POST /truemoney/v1/verify (deprecated)
scanBankSlipByPayload(payload) POST /bank/v0/verifyByPayload
scanBankSlipByFile(file) POST /bank/v0/verifyByFile
scanBankSlipByBase64(encoded) POST /bank/v0/verifyByBase64
scanBankSlipByImage(file) same, base64 encoding the image for you
getAllTransactions(...) GET /transaction/getAllTransactions

Account and management — needs the User API Token

Method API
getUserCredit() GET /user/credit
getApplications() GET /management/application
getApplication(app_id) GET /management/application/:id
createApplication(name, description, whitelist_ips) POST /management/application
updateApplication(app_id, name, description, whitelist_ips) PUT /management/application/:id
deleteApplication(app_id) DELETE /management/application/:id
getApplicationApiKey(app_id) GET /management/application/:id/api_key
rotateApplicationApiKey(app_id) POST /management/application/:id/api_key/rotate

The two credentials are different things: the Application API Key verifies slips, and the User API Token manages applications and reads your credit. Configure both if you use both.

client = Slip2SureAPI("YOUR_API_KEY", user_api_token="YOUR_USER_API_TOKEN")

Bank slip from an image

with open("FILE_PATH", "rb") as f:
    result = await client.scanBankSlipByFile(f.read())

Transaction history

from slip2sure import SlipType, TransactionStatus

page = await client.getAllTransactions(
    page=0,
    size=50,
    status=TransactionStatus.COMPLETED,
    slip_type=SlipType.BANK_SLIP_VERIFY,
)
for item in page.items:
    print(item.id, item.amount, item.status)
print("last page:", page.pagination.is_end_page)

The date filter is named from_ because from is a Python keyword. Page 0 is a real page, so passing page=0 still sends the filter.

Credit and applications

credit = await client.getUserCredit()
print(credit.credit)        # a float, parsed from the API's string

app = await client.createApplication(
    "My store",
    "",
    ["203.0.113.10"],       # ["*"] allows every IP
)
# app.api_key is returned in full only here, so store it now.

Configuration

client = Slip2SureAPI(
    "YOUR_API_KEY",
    base_url="https://api.slip2sure.com/api/v0",
    timeout=30.0,        # seconds for the whole call, retries included; None disables
    max_retries=2,       # 0 disables
    retry_backoff=0.5,   # base delay for exponential backoff
    session=None,        # supply your own aiohttp.ClientSession
    user_api_token="",   # needed by the credit and management endpoints
)

When you pass a session, you keep ownership of it: close() leaves it open for you to manage.

Retries

Transient failures are retried with exponential backoff and full jitter, and a Retry-After response header is honoured when present.

Only 408, 429, 502, 503 and 504 are retried, along with connection errors and timeouts. 500 is deliberately not retried: verification costs credit, and a request that failed after being processed could otherwise be billed twice.

createApplication and rotateApplicationApiKey are never retried at all, whatever the status: a retried gateway error could create a second application or rotate the key twice and discard the key the first attempt returned.

Error handling

Every failure is a Slip2SureError carrying .code, .message and .status_code. Catch a subclass to handle one family of failures:

from slip2sure import (
    ErrorCode,
    Slip2SureAuthError,
    Slip2SureCreditError,
    Slip2SureError,
    Slip2SureNotFoundError,
    Slip2SureServerError,
    Slip2SureTransportError,
    Slip2SureValidationError,
)

try:
    result = await client.scanBankSlipByPayload("YOUR_QR_CODE")
except Slip2SureCreditError:
    ...                      # out of credit
except Slip2SureNotFoundError:
    ...                      # not a real slip
except Slip2SureError as exc:
    print(exc.code, exc.message, exc.status_code)
Exception Codes
Slip2SureAuthError INVALID_HEADER, UNAUTHORIZED, APPLICATION_LOCKED
Slip2SureValidationError VALIDATE_ERROR, FILE_REQUIRED, FILE_TOO_LARGE, FILE_NOT_SUPPORTED
Slip2SureCreditError CREDIT_INSUFFIENCT
Slip2SureNotFoundError SLIP_NOT_EXIST
Slip2SureServerError SERVER_ERROR, SERVICE_ERROR, SERVICE_TIMEOUT
Slip2SurePendingError SLIP_BBL_PENDING
Slip2SureTransportError connection failures and timeouts

Slip2SureAuthError also covers IP_NOT_ALLOWED, and Slip2SureNotFoundError also covers SLIP_QRCODE_NOT_EXIST and TRANSACTION_NOT_EXIST; v1 defined none of those four codes.

Slip2SurePendingError is worth handling on its own: Bangkok Bank returns SLIP_BBL_PENDING for a few minutes after a transfer, and the same slip succeeds on a later attempt.

A code this SDK predates still raises a plain Slip2SureError with .code intact, rather than being flattened or raising a KeyError.

Migrating from v1

  • v1 did not import on Python 3.10 or 3.11. client.py used a nested same-quote f-string, which is only valid from 3.12, while the package declared python_requires=">=3.10". This release works on 3.10 upward.
  • scanBankSlipByPayload no longer prints the response to stdout.
  • Timestamps are datetime, not str. info.transDateTime and info.paid_at are parsed, matching the Go SDK.
  • Optional fields now default instead of being required. A slip whose account omitted name used to fail validation outright; ref1–ref3, paidLocalCurrency, countryCode and toMerchantId are likewise optional.
  • scanTruemoneySlip now calls the v2 endpoint, which also returns info.payload, info.account_from_name and info.account_to_name. The v1 endpoint is still reachable as scanTruemoneySlipV1.
  • Slip2SureBankSlip and Slip2SureTruemoney inherit Slip2SureBase. credit and is_exist are unchanged.
  • Errors gained .code, .message and .status_code, plus the subclasses above. The old .errorCode and .errorMessage attributes still work.
  • An uploaded file's MIME type is now image/jpeg rather than the invalid image/jpg.
  • Dependencies are ranges, not exact pins, so installing the SDK no longer forces a specific pydantic or aiohttp on your project.
  • There is now a 30 second default timeout. v1 had none.

Tests

python -m unittest discover

LICENSE

MIT

Metadata

Release files for slip2sure 2.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for slip2sure 2.0.1
File Size Uploaded Provenance Actions
slip2sure-2.0.1.tar.gz 27.2 kB Without provenance Details for slip2sure-2.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for slip2sure 2.0.1
File Interpreter ABI Platform Actions
slip2sure-2.0.1-py3-none-any.whl Python 3 none any Details for slip2sure-2.0.1-py3-none-any.whl

Total release size: 47.2 kB

Release files / slip2sure-2.0.1.tar.gz

Download URL slip2sure-2.0.1.tar.gz
Size 27.2 kB
Tags Source
SHA-256 checksum
How to use checksums
388cf03da26533d1b5ee2369b30689227093942d6bfde420f03fd78bfe196075
BLAKE2b-256 checksum
How to use checksums
984927633dc96cbe5cf5610e9a9db6ad4ba5eda0936e1e282f33fce00c1b2408
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.16

Release files / slip2sure-2.0.1-py3-none-any.whl

Download URL slip2sure-2.0.1-py3-none-any.whl
Size 20.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e42a164725359d3249e8d7f873661032a3448f5784915c050724b35e3d2ca5e7
BLAKE2b-256 checksum
How to use checksums
599917effbd8078e0847525f2fc2d77c03308f6e31ae4f5a701531900e4d99d6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.16

Security for slip2sure 2.0.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.

Release history Release notifications | RSS feed

This release

2.0.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page