The official Python client for the Fintoc API.
Project description
Fintoc meets Python 🐍
You have just found the Python-flavored client of Fintoc.
Table of Contents
Installation
Install using pip!
pip install fintoc
Note: This SDK requires Python 3.6+.
Usage
The idea behind this SDK is to stick to the API design as much as possible, so that it feels ridiculously natural to use even while only reading the raw API documentation.
Quickstart
To be able to use this SDK, you first need to get your secret API Key from the Fintoc Dashboard. Once you have your API key, all you need to do is initialize a Fintoc
object with it and you're ready to start enjoying Fintoc!
from fintoc import Fintoc
client = Fintoc("your_api_key")
# list all succeeded payment intents since the beginning of 2025
payment_intents = client.payment_intents.list(since="2025-01-01", status="succeeded")
for pi in payment_intents:
print(pi.created_at, pi.amount, pi.customer_email)
# Get a specific payment intent
payment_intent = client.payment_intents.get("pi_12345235412")
print(payment_intent.customer_email)
Calling endpoints
The SDK provides direct access to Fintoc API resources following the API structure. Simply use the resource name and follow it by the appropriate action you want.
Notice that not every resource has all of the methods, as they correspond to the API capabilities.
list
You can use the list
method to list all the instances of the resource:
webhook_endpoints = client.webhook_endpoints.list()
The list
method returns a generator with all the instances of the resource. This method can also receive the arguments that the API receives for that specific resource. For example, the PaymentIntent
resource can be filtered using since
and until
, so if you wanted to get a range of payment intents
, all you need to do is to pass the parameters to the method:
payment_intents = client.payment_intents.list(since="2025-01-01", until="2025-02-01")
You can also pass the lazy=False
parameter to the method to force the SDK to return a list of all the instances of the resource instead of the generator. Beware: this could take very long, depending on the amount of instances that exist of said resource:
payment_intents = client.payment_intents.list(since="2025-01-01", until="2025-02-01", lazy=False)
isinstance(payment_intents, list) # True
get
You can use the get
method to get a specific instance of the resource:
payment_intent = client.payment_intents.get("pi_8anqVLlBC8ROodem")
create
You can use the create
method to create an instance of the resource:
webhook_endpoint = client.webhook_endpoints.create(
url="https://webhook.site/58gfb429-c33c-20c7-584b-d5ew3y3202a0",
enabled_events=["link.credentials_changed"],
description="Fantasting webhook endpoint",
)
The create
method of the managers creates and returns a new instance of the resource. The attributes used for creating the object are passed as kwargs
, and correspond to the parameters specified by the API documentation for the creation of said resource.
update
You can use the update
method to update an instance of the resource:
webhook_endpoint = client.webhook_endpoints.update(
"we_8anqVLlBC8ROodem",
enabled_events=["account.refresh_intent.succeeded"],
disabled=True,
)
The update
method updates and returns an existing instance of the resource using its identifier to find it. The first parameter of the method corresponds to the identifier being used to find the existing instance of the resource. The attributes to be modified are passed as kwargs
, and correspond to the parameters specified by the API documentation for the update action of said resource.
delete
You can use the delete
method to delete an instance of the resource:
deleted_identifier = client.webhook_endpoints.delete("we_8anqVLlBC8ROodem")
The delete
method deletes an existing instance of the resource using its identifier to find it and returns the identifier.
v2 Endpoints
To call v2 API endpoints, like the Transfers API, you need to prepend the resource name with the v2
namespace, the same as the API does it:
transfer = client.v2.transfers.create(
amount=49523,
currency="mxn",
account_id="acc_123545",
counterparty={"account_number": "014180655091438298"},
metadata={"factura": "14814"},
)
Nested actions or resources
To call nested actions just call the method as it appears in the API. For example to simulate receiving a transfer for the Transfers product you can do:
transfer = client.v2.simulate.receive_transfer(
amount=9912400,
currency="mxn",
account_number_id="acno_2vF18OHZdXXxPJTLJ5qghpo1pdU",
)
Webhook Signature Validation
To ensure the authenticity of incoming webhooks from Fintoc, you should always validate the signature. The SDK provides a WebhookSignature
class to verify the Fintoc-Signature
header
WebhookSignature.verify_header(
payload=request.get_data().decode('utf-8'),
header=request.headers.get('Fintoc-Signature'),
secret='your_webhook_secret'
)
The verify_header
method takes the following parameters:
payload
: The raw request body as a stringheader
: The Fintoc-Signature header valuesecret
: Your webhook secret key (found in your Fintoc dashboard)tolerance
: (Optional) Number of seconds to tolerate when checking timestamp (default: 300)
If the signature is invalid or the timestamp is outside the tolerance window, a WebhookSignatureError
will be raised with a descriptive message.
For a complete example of handling webhooks, see examples/webhook.py.
Idempotency Keys
You can provide an Idempotency Key using the idempotency_key
argument. For example:
transfer = client.v2.transfers.create(
idempotency_key="12345678910"
amount=49523,
currency="mxn",
account_id="acc_123545",
counterparty={"account_number": "014180655091438298"},
metadata={"factura": "14814"},
)
Generate the JWS Signature
Some endpoints need a JWS Signature, in addition to your API Key, to verify the integrity and authenticity of API requests. To generate the signature, initialize the Fintoc client with the jws_private_key
argument, and the SDK will handle the rest:
import os
from fintoc import Fintoc
# Provide a path to your PEM file
client = Fintoc("your_api_key", jws_private_key="private_key.pem")
# Or pass the PEM key directly as a string
client = Fintoc("your_api_key", jws_private_key=os.environ.get('JWS_PRIVATE_KEY'))
# You can now create transfers securely
Serialization
Any resource of the SDK can be serialized! To get the serialized resource, just call the serialize
method!
payment_intent = client.payment_intents.list(lazy=False)[0]
serialization = payment_intent.serialize()
The serialization corresponds to a dictionary with only simple types, that can be JSON-serialized.
Acknowledgements
The first version of this SDK was originally designed and handcrafted by @nebil, ad piscolem. He built it with the help of Gianni Roberto's Picchi 2.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file fintoc-2.9.0.tar.gz
.
File metadata
- Download URL: fintoc-2.9.0.tar.gz
- Upload date:
- Size: 20.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
24da50f7faf881729d4f1a6ac282fba260c7950d943ae78bb9e31cd5ff3c075d
|
|
MD5 |
6b30e8851cc5eb0ca1b8fd141a613582
|
|
BLAKE2b-256 |
6713317eaedd7a8c898d504f886fe60d4bf89b9b102722f832450b00a44c78f3
|
File details
Details for the file fintoc-2.9.0-py3-none-any.whl
.
File metadata
- Download URL: fintoc-2.9.0-py3-none-any.whl
- Upload date:
- Size: 35.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
d5e2eb8c268107e0c6c56d87b9ec7d5008515654266cc2c7a87d0425657cf8cd
|
|
MD5 |
f30f38106e3033f6337c123149872c61
|
|
BLAKE2b-256 |
a22e88c6a8592ecc2bd63ee620504ff52754a267658c76f61e8580f736ee2bce
|