python-redsys
A lightweight client for the RedSys TPV Virtual: it builds signed requests and verifies and parses responses, for the redirect connection (browser form) and the direct connection (server-to-server REST). For Django, see django-redsys.
Installation
pip install python-redsys
pip install "python-redsys[http]" # optional: sends direct-connection requests with httpx
Python 3.10 or later. Runtime dependencies: cryptography and pydantic 2.
Redirect connection
from decimal import Decimal
from redsys import generate_order
from redsys.clients import RedirectClient
client = RedirectClient(secret_key="...", merchant_code="999008881", terminal=1, sandbox=True)
# 1. Build the signed request.
request = client.payment(
order=generate_order(),
amount=Decimal("10.56"), # euros unless currency= says otherwise
merchant_url="https://example.com/redsys/notification",
url_ok="https://example.com/ok",
url_ko="https://example.com/ko",
)
# 2. The browser POSTs request.to_dict() (three fields) to request.endpoint.
# 3. Verify and read the notification RedSys posts to merchant_url.
response = client.parse_response(received_fields)
if response.is_paid():
...
else:
print(response.response_code, response.describe("en"))
The redirect connection takes payment(), preauthorization(), authentication() and refund_without_original().
Direct connection
from redsys.clients import DirectClient
client = DirectClient(secret_key="...", merchant_code="999008881", terminal=1, sandbox=True)
response = client.refund(order="000000001", amount=Decimal("10.56")).send() # signs, posts, verifies
response.is_refunded()
AsyncDirectClienthas the same methods;await request.send().- Without the
httpextra, POSTrequest.to_dict()torequest.endpointwith any HTTP client and pass the JSON answer toclient.parse_response(). - Operations:
payment,preauthorization,confirmation,partial_confirmation,refund,refund_without_original,void,payment_cancellation,authentication,authentication_confirmation,pay_gold, andrequest(transaction_type, ...)for any other type inredsys.transactions.
3-D Secure
Card data sent by the merchant goes through EMV3DS. The library builds each call; the browser steps (3DSMethod iframe, challenge form) are the integrator's.
from redsys import emv3ds, threeds
card = dict(pan="4548810000000003", expiry_date="4912", cvv2="123")
operation = dict(order=generate_order(), amount=Decimal("10.56"))
config = client.inicia_payment(**operation, **card).send()
# Optional 3DSMethod: the browser posts threeds.method_data(...) to config.three_ds_method_url.
authentication = threeds.authentication_data(
three_ds_server_trans_id=config.three_ds_server_trans_id,
notification_url="https://example.com/redsys/3ds",
protocol_version=config.protocol_version,
browser=threeds.browser_info(...), # collected by the merchant page
three_ds_comp_ind=emv3ds.METHOD_COMPLETED,
)
response = client.payment(emv3ds=authentication, **operation, **card).send()
if response.requires_challenge():
# The browser posts response.creq to response.acs_url; the ACS posts cres back to notification_url.
response = client.challenge_response(
cres=cres, protocol_version=response.protocol_version, **operation, **card
).send()
Stored cards and merchant-initiated payments
from redsys import cof, options, sca
first = client.payment(..., identifier=cof.REQUEST_TOKEN, cof_ini=cof.INITIAL, cof_type=cof.RECURRING)
# After 3-D Secure: first.identifier is the token, first.cof_txnid the network transaction id.
client.payment(
order=generate_order(), amount=Decimal("10.56"),
identifier=token, cof_txnid=cof_txnid, cof_ini=cof.SUBSEQUENT, cof_type=cof.RECURRING,
excep_sca=sca.MIT, direct_payment=options.DIRECT_PAYMENT,
).send()
Payment methods
- Bizum, redirect:
pay_methods=pay_methods.BIZUMonpayment(). - Bizum Request-to-Pay, direct: the same, plus
bizum_mobile_numberandendpoint=client.url(environments.RTP_TRATA_PATH); readresponse.rtp_statusandresponse.rtp_response(redsys.bizum). - PayGold link:
pay_gold(customer_mobile=..., customer_sms_text=f"{paygold.SMS_AMOUNT} {paygold.SMS_URL}"); the link isresponse.url_pago_2_fases. - Google Pay and Apple Pay:
xpay_data(orxpay_decoded_data) withxpay_type=xpay.GOOGLEandxpay_origen=xpay.WEB. - inSite:
idoper=with the token from RedSys's JavaScript, on a directpayment().
Configuration
| Option | Use |
|---|---|
environment= |
environments.TEST, PROD, INTE or DESA; sandbox=True is TEST |
Client.from_api_key(api_key) |
Reads the environment, merchant code, terminal and secret key from a RedSys API key |
currency= |
Default currency of the client (currencies.EUR unless set); a call can override it |
signature_version= |
HMAC_SHA512_V2 (default), HMAC_SHA512_V1 or legacy HMAC_SHA256_V1, from redsys.clients |
module= |
Ds_Merchant_Module of every request: python-redsys/<version> by default, another text, or None to leave it out |
endpoint= on an operation |
Sends that request to another HTTPS URL; client.url(path) builds one |
Every documented value has a named constant in redsys (transactions, currencies, languages, pay_methods, cof, sca, options, emv3ds, cards, responses, ...). Use them instead of literals.
Errors
Fields are validated when the operation method is called, before anything is signed or sent. Any invalid parameter raises a ValueError subclass:
| Problem | Raised |
|---|---|
| A field with the wrong type or format, a missing required field, a misspelled or 1.x field name, an unknown currency or transaction type | pydantic.ValidationError; .errors() lists each field |
A transaction type that contradicts the operation or the redirect connection, a non-HTTPS endpoint, an invalid API key or environment |
redsys.exceptions.ValidationError |
A signature that does not match in parse_response() |
ValueError |
A payload in parse_response() or an answer in send() that is not a well-formed RedSys result, for example without a signature or not a Base64-encoded JSON object |
redsys.exceptions.ValidationError |
| RedSys answers with an error code instead of a signed result | redsys.exceptions.ResponseError; .error_code holds the SISnnnn code |
An HTTP error status from RedSys in send() |
httpx.HTTPStatusError |
A parameter the library does not model yet can be passed by its wire name (Ds_Merchant_...): it is sent as given, with an UnknownParameterWarning.
Response codes
response.response_code is the integer Ds_Response; response.is_paid() (0 to 99), is_refunded() (900), is_canceled() (400) and is_authorized() (any of them) cover the common outcomes. response.describe(language) and redsys.codes.describe(code, language) give the meaning of any Ds_Response, SISnnnn or Bizum BIZnnnnn code. Table: docs/response-codes.md.
Status
| Version | 2.2.1; 1.x receives fixes until 2026-12-31 (migration guide) |
| Python | 3.10 to 3.15 |
| RedSys documents followed | Redirection guide 4.2, REST guide 4.0.1, Bizum guide 2.6, inSite guide 4.1, PayGold guide 1.8.2, Google Pay guide 1.9, Apple Pay guide 3.2, "Parámetros de entrada y salida" page |
| Verified against the RedSys test environment | Redirect in a browser with the 3DS challenge; direct end to end (frictionless and challenged 3DS, 3DSMethod, refund, void, payment cancellation, stored-card merchant-initiated charge), in all three signature versions |
Reference
docs/redirect-connection.mdanddocs/direct-connection.md: protocol reference for each connection.docs/response-codes.md: response, SIS and Bizum codes.docs/official-libraries.md: equivalences for integrators of RedSys's PHP and Java libraries.CONTRIBUTING.md: development setup, checks and live tests.
Metadata
Release files for python-redsys 2.2.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 |
|---|---|---|---|---|
| python_redsys-2.2.1.tar.gz | 101.2 kB | With provenance | Details for python_redsys-2.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| python_redsys-2.2.1-py3-none-any.whl | Python 3 | none | any | Details for python_redsys-2.2.1-py3-none-any.whl |
Total release size: 185.4 kB
Release files / python_redsys-2.2.1.tar.gz
| Download URL | python_redsys-2.2.1.tar.gz |
|---|---|
| Size | 101.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1c923478340efefa3c67b7f32384e2ef048cabf4aa192aecc4c84b61a5d7dea4
|
|
BLAKE2b-256 checksum How to use checksums |
3e9353f8d446cca33cd24b50a257f473a1834dd6860a8c633832b19f867b7e49
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 14, 2026.
Transparency logRelease files / python_redsys-2.2.1-py3-none-any.whl
| Download URL | python_redsys-2.2.1-py3-none-any.whl |
|---|---|
| Size | 84.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ed9ed516240c86e752e911d94601bf2080f78d2b0fbb5177ff28227dc3f24658
|
|
BLAKE2b-256 checksum How to use checksums |
79ad57b70e2a03ebe0b3a95bbac1cf7d69745afed28562ad7e2f865244609a1c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 14, 2026.
Transparency logSecurity for python-redsys 2.2.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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for python_redsys-2.2.1.tar.gz
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 Nov 14, 2026.
Transparency logA 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.