Skip to main content

A modern Python SDK for SIBS Gateway payment integrations.

Project description

PySIBS

A modern, typed, developer-friendly Python SDK for SIBS Gateway payment integrations.

PySIBS provides a clean API for payments, refunds, captures, cancellations, status checks and webhook verification. It is framework-agnostic and works in Django, FastAPI, Flask, Celery, CLI scripts — anywhere Python runs.

Project status: Alpha. The public API surface is intentionally small and stable, but endpoint/field details are still being validated against SIBS' official documentation. Every response exposes a raw_response so you are never blocked by a field PySIBS has not yet normalized. See Caveats.

Features

  • Synchronous (SIBSClient) and asynchronous (AsyncSIBSClient) clients
  • Create payments (purchase or pre-authorization), check status, refund, capture, cancel
  • MB WAY purchase flow and MULTIBANCO reference parsing
  • AES-GCM webhook decryption + acknowledgement helper (the scheme SIBS actually uses)
  • Typed Pydantic models with normalized statuses (PaymentStatus)
  • Safe money handling with Decimal (floats are rejected)
  • A clear exception hierarchy — raw httpx errors never leak out
  • Fully typed (py.typed), ruff + mypy --strict clean

Installation

pip install pysibs

# For AES-GCM webhook decryption (pulls in `cryptography`):
pip install "pysibs[webhooks]"

Requires Python 3.10+.

Configuration

Construct a client directly:

from pysibs import SIBSClient

client = SIBSClient(
    api_key="your_api_key",
    terminal_id="your_terminal_id",
    environment="sandbox",  # or "production"
)

…or from environment variables (SIBS_API_KEY, SIBS_TERMINAL_ID, SIBS_ENVIRONMENT, and optionally SIBS_CLIENT_ID, SIBS_WEBHOOK_SECRET):

client = SIBSClient.from_env()

The core library never reads .env — only the bundled examples do, via python-dotenv. See .env.example.

Create a payment

payment = client.create_payment(
    amount="10.00",                 # str, int or Decimal — never float
    currency="EUR",
    merchant_transaction_id="ORDER-123",
    return_url="https://example.com/payment/success",
    cancel_url="https://example.com/payment/cancel",
    payment_methods=["CARD", "MBWAY", "MULTIBANCO"],
)

print(payment.id)
print(payment.status)        # normalized PaymentStatus
print(payment.redirect_url)
print(payment.raw_response)  # untouched SIBS response

Check payment status

status = client.get_payment_status("payment_123")
print(status.status)      # normalized PaymentStatus
print(status.raw_status)  # original value from SIBS

Refunds

# Full refund
client.refund_payment(payment_id="payment_123")

# Partial refund
client.refund_payment(payment_id="payment_123", amount="10.00", merchant_refund_id="REF-1001")

Capture & cancel

Create a pre-authorization, then capture (or cancel) it later:

auth = client.create_payment(
    amount="25.50", merchant_transaction_id="ORDER-1", transaction_type="AUTH"
)
client.capture_payment(payment_id=auth.id, amount="25.50")
# or release it:
client.cancel_payment(auth.id)

MB WAY

After creating a payment with the MBWAY method, trigger the purchase with the shopper's phone (the result arrives via webhook):

payment = client.create_payment(
    amount="10.00", merchant_transaction_id="ORDER-2", payment_methods=["MBWAY"]
)
client.pay_with_mbway(
    payment_id=payment.id,
    transaction_signature=payment.signature,
    customer_phone="351#911234567",
)

MULTIBANCO reference

payment = client.create_payment(
    amount="25.50", merchant_transaction_id="ORDER-3", payment_methods=["REFERENCE"]
)
ref = payment.payment_reference
print(ref.entity, ref.reference, ref.expire_date)  # show these to the shopper

Async usage

from pysibs import AsyncSIBSClient

async with AsyncSIBSClient.from_env() as client:
    payment = await client.create_payment(amount="10.00", merchant_transaction_id="ORDER-1")

Webhooks

SIBS encrypts webhook bodies with AES-GCM (it does not sign them). Decrypt, parse, then acknowledge with HTTP 200 so SIBS stops retrying:

from pysibs import decrypt_webhook, parse_webhook, build_acknowledgement

data = decrypt_webhook(
    body=raw_body,                                   # base64 ciphertext (request body)
    iv=request.headers["X-Initialization-Vector"],
    auth_tag=request.headers["X-Authentication-Tag"],
    secret=WEBHOOK_SECRET_KEY,                        # from the SIBS Backoffice
)
event = parse_webhook(data)
print(event.payment_id, event.status, event.payment_reference)

ack = build_acknowledgement(event)   # return this JSON with HTTP 200

Requires pip install "pysibs[webhooks]". See docs/webhooks.md for details. The legacy verify_webhook_signature() helper remains for custom schemes but SIBS Gateway does not use HMAC.

Error handling

All exceptions inherit from SIBSError:

Exception Raised when
SIBSConfigurationError The client is misconfigured (missing credentials, bad environment).
SIBSValidationError Input fails local validation (e.g. a float amount, empty id).
SIBSAuthenticationError SIBS rejects credentials (HTTP 401/403).
SIBSAPIError Other API errors (carries status_code and response_body).
SIBSTimeoutError The request times out (or HTTP 408).
SIBSConnectionError SIBS cannot be reached (DNS/TCP/TLS).
SIBSInvalidWebhookSignature A webhook signature fails verification.
from pysibs import SIBSError, SIBSAuthenticationError

try:
    client.create_payment(amount="10.00", merchant_transaction_id="ORDER-1")
except SIBSAuthenticationError:
    ...  # bad credentials
except SIBSError as exc:
    ...  # any other PySIBS failure

PCI DSS note

This SDK does not store or process cardholder data by itself. However, some SIBS server-to-server card payment flows may require the merchant environment to be PCI DSS compliant. Always validate your integration scope with SIBS and your PCI advisor.

PySIBS deliberately:

  • never stores PAN or CVV,
  • never logs Authorization headers or credentials,
  • ships no examples containing real card data.

Caveats — unverified details

SIBS' public documentation does not pin down every endpoint, field name and signing detail unambiguously, and they can vary by product/environment. Where there was ambiguity, PySIBS:

  1. keeps the wire format isolated in pysibs/_payloads.py and base URLs in pysibs/config.py, so they are trivial to adjust in one place;
  2. preserves the full raw_response / raw_payload on every model;
  3. never sends undocumented headers (e.g. idempotency — see pysibs/idempotency.py).

Before going to production, verify the endpoints, payloads and webhook signature scheme against the current official SIBS documentation.

Python compatibility

Tested on CPython 3.10, 3.11, 3.12 and 3.13.

Roadmap

  • 0.1.0SIBSClient/AsyncSIBSClient, create/status/refund/capture/cancel, webhook parsing, typed models, docs.
  • 0.2.0 — AES-GCM webhook decryption + acknowledgement, MB WAY purchase flow, MULTIBANCO reference parsing, AUTH/PURS transaction types. ✅
  • 0.3.0 — card server-to-server / 3DS flow, more payment-method models.
  • 1.0.0 — stable API once the SIBS contract is fully confirmed end-to-end.

Contributing

See CONTRIBUTING.md. Security issues: see SECURITY.md.

License

MIT © Robert Benitez

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pysibs-0.2.0.tar.gz (29.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pysibs-0.2.0-py3-none-any.whl (29.1 kB view details)

Uploaded Python 3

File details

Details for the file pysibs-0.2.0.tar.gz.

File metadata

  • Download URL: pysibs-0.2.0.tar.gz
  • Upload date:
  • Size: 29.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pysibs-0.2.0.tar.gz
Algorithm Hash digest
SHA256 57ae0bbb4f4103d04909a31a776c2f10ddececfab78f415c07549af8a4f8cc7b
MD5 3a60689934fa597269dbd5bb501fed5a
BLAKE2b-256 00f67c645cfcfc427b3cbb7ce4d5adf98989bf5c2340fe65037ab1ac3d4c0c59

See more details on using hashes here.

Provenance

The following attestation bundles were made for pysibs-0.2.0.tar.gz:

Publisher: publish.yml on robertruben98/sibs-gateway-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pysibs-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: pysibs-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 29.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pysibs-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a54b6a8d13cf5ede016fda6633fe321ea1d5b24cd423de04b7a3ab6a2ced3f5d
MD5 559285e83d3cf4ec80d479ff74ba4b80
BLAKE2b-256 c69dc62f084994135f2a73649eaf91f13950f2d89c766a16fe2c81fc34473b33

See more details on using hashes here.

Provenance

The following attestation bundles were made for pysibs-0.2.0-py3-none-any.whl:

Publisher: publish.yml on robertruben98/sibs-gateway-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page