Skip to main content

Welcome to python-redsys!

CI PyPI Python 3.8+ License: MIT

A simple, lightweight client to handle payments through the RedSys platform, using its redirect connection (browser form POST).

The library only builds the signed request and verifies/parses the response. It makes no network or browser calls of its own: the payment form is submitted from the cardholder's browser.

Installation

pip install "python-redsys>=1.2,<2"

# or with Poetry
poetry add "python-redsys@^1.2"

Requires Python 3.8+. Runtime dependency: pycryptodome.

Usage

The client prepares a request from a dict of parameters and verifies the response. Parameter values are validated on construction (ValueError on an unknown parameter or an invalid value, TypeError when amount is not a Decimal); order has 12 characters (4 digits followed by 8 alphanumerics), and amount is a Decimal, serialized to integer minor units on the wire. The allowed values for currency, transaction_type and consumer_language are in redsys.constants.

Using redirect connection

1. Build a signed request

from decimal import Decimal, ROUND_HALF_UP
from redsys.client import RedirectClient
from redsys.constants import EUR, STANDARD_PAYMENT

client = RedirectClient(secret_key="sq7HjrUOBfKmC576ILgskD5srU870gJ7")

post_parameters = client.prepare_request({
    "merchant_code": "999008881",
    "terminal": "1",
    "transaction_type": STANDARD_PAYMENT,
    "currency": EUR,
    "order": "000000000001",
    # The amount is a Decimal; pre-quantize to two decimals.
    "amount": Decimal("10.56489").quantize(Decimal(".01"), ROUND_HALF_UP),
    "merchant_url": "https://example.com/redsys/response",
    "url_ok": "https://example.com/ok",
    "url_ko": "https://example.com/ko",
    "merchant_name": "Example Commerce",
    "product_description": "Products of Example Commerce",
})  # Ds_SignatureVersion / Ds_MerchantParameters / Ds_Signature

The secret key, merchant code 999008881 and terminal 1 are the RedSys public test merchant's. Ds_MerchantParameters and Ds_Signature are returned as bytes; decode them before rendering them in an HTML form.

Bizum: add "payment_method": "z" (and optionally "mobile_number") to the parameters.

2. Communication step

Auto-submit an HTML form (method="POST") with the three post_parameters fields to the RedSys endpoint:

  • Test: https://sis-t.redsys.es:25443/sis/realizarPago
  • Production: https://sis.redsys.es/sis/realizarPago

RedSys notifies the result both as a server-to-server POST to merchant_url and as a browser redirect to url_ok / url_ko.

3. Verify and read the response

create_response() takes the received Ds_Signature and Ds_MerchantParameters and raises ValueError on signature mismatch.

response = client.create_response(signature, merchant_parameters)  # as RedSys posted them back

if response.is_paid:
    ...  # actions after a successful payment
else:
    raise Exception(f"declined with code {response.code}")

Response predicates (per the RedSys documentation):

  • response.is_paid: response code between 0 and 99.
  • response.is_canceled: response code 400.
  • response.is_refunded: response code 900.
  • response.is_authorized: paid, refunded or canceled.

response.code is the RedSys code as an int, and response.message its Spanish description (None for a code without one). Decoded fields (response.order, response.amount as a Decimal, ...) read as attributes, None when absent; response.parameters holds every decoded parameter: listed ones under their attribute name (amount), unlisted ones under their original Ds_* key.

Signature version

The 1.x line signs with HMAC_SHA256_V1 (3DES + HMAC-SHA256), the legacy scheme still accepted by RedSys. HMAC_SHA512_V1 requires 2.x.

Support

The 1.x line receives fixes until 2026-12-31.

Contributing

Contributions that keep the lightweight philosophy are welcome.

Metadata

Release files for python-redsys 1.2.2

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

Source distribution (sdist)

Source distribution for python-redsys 1.2.2
File Size Uploaded
python_redsys-1.2.2.tar.gz 11.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for python-redsys 1.2.2
File Interpreter ABI Platform
python_redsys-1.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 25.6 kB

Release files / python_redsys-1.2.2.tar.gz

Download URL python_redsys-1.2.2.tar.gz
Size 11.8 kB
Tags Source
SHA-256 checksum
How to use checksums
8c6668f5f2d01b41c26e6aa4cc9156b523d93d3e5c72b5dc93f17737188c3d6b
BLAKE2b-256 checksum
How to use checksums
67dd59c9dc572d7ce42bcd2b56fa8f2cd22aed419a8fcdf6270036426b2bf898
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 17, 2026.

Transparency log

Release files / python_redsys-1.2.2-py3-none-any.whl

Download URL python_redsys-1.2.2-py3-none-any.whl
Size 13.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
71f5e04659560e58ef6f8963f5557ce8efc36b8e6510eda80cc1dfe0e140605c
BLAKE2b-256 checksum
How to use checksums
e7765dbc144982bbd4a464221a353862e7b52c83539c93ce6ad764963fd1c577
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 17, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.2.2 This release

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

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