A framework-agnostic Python library to manage Brazilian bank slips (boletos) across multiple banks.
Project description
PyBank Slip
PyBank Slip is an independent, modern, and robust Python library designed to unify and simplify communication with bank slip (Boleto and Pix) APIs in Brazil. It manages all the complexity of authentication (OAuth2 and mTLS) and abstracts the bank routes, allowing your application (like ERPs or E-commerces) to focus solely on building the bank slip payload.
🏦 Supported Banks
The library currently supports the V2 APIs of the following institutions:
- Banco do Brasil (API de Cobranças V2)
- Santander (API de Cobrança / Workspace V2)
⚙️ How it Works?
The library adopts the Factory/Adapter design pattern. The core focuses on the BankSlipManager, which receives the global credentials and the target bank, and returns an instance (Adapter) ready for use. The Adapter handles:
- Automatically fetching the Access Token (Bearer) using the credentials.
- Attaching the ICP-Brasil Certificate (mTLS) required by the APIs.
- Defensive handling against malformed payloads (
safe_json_loads) returned by the bank servers (e.g., truncated JSONs or invalid fields). - Managing the selected environment (Production vs Sandbox).
📌 Required Parameters
The library requires configurations in three main areas:
1. OAuthCredentials
A structure that stores the App data created in the bank's developer portal:
client_id: The Client ID (App ID).client_secret: The Client Secret.app_key(Optional): Primarily used by Banco do Brasil (gw-dev-app-key).
2. CertificateAuth (mTLS)
Digital certificate configuration for two-way SSL/TLS encryption (required by Santander and BB).
cert_path: Absolute path to the.pemfile of the client certificate (Public Key).key_path: Absolute path to the.pemfile of the private key.
3. Manager/Adapter
Parameters passed when instantiating the adapter:
bank: Bank string identifier ('bb'or'santander').credentials: Instance ofOAuthCredentials.environment: Environment string ('production'or'sandbox').cert_auth: Instance ofCertificateAuth.workspace_id(Only Santander): The financial workspace ID.
🚀 Abstracted Routes and Features
Each Adapter abstracts the raw HTTP calls into the following built-in methods:
generate_bank_slip(payload: dict)
Sends the bank slip registration request.
- Banco do Brasil:
POST /cobrancas/v2/boletos - Santander:
POST /collection_bill_management/v2/workspaces/{workspace_id}/bank_slips
list_bank_slips(filters: dict)
Queries issued bank slips using filters (Document, Date, etc).
- Banco do Brasil:
GET /cobrancas/v2/boletos - Santander:
GET /collection_bill_management/v2/workspaces/{workspace_id}/bank_slips
cancel_bank_slip(bank_slip_id: str, payload: dict)
Requests the cancellation/write-off of the bank slip.
- Banco do Brasil:
POST /cobrancas/v2/boletos/{id}/baixar - Santander:
PATCH /collection_bill_management/v2/workspaces/{workspace_id}/bank_slips/{id}
edit_bank_slip(bank_slip_id: str, payload: dict)
Allows editing conditions (Due Date, Value, Discounts) of the bank slip.
- Banco do Brasil:
PATCH /cobrancas/v2/boletos/{id} - Santander:
PATCH /collection_bill_management/v2/workspaces/{workspace_id}/bank_slips/{id}
(For Santander, there are also exclusive utility methods such as search_workspaces inside the Adapter).
💻 Practical Usage Example
from pybank_slip import BankSlipManager, OAuthCredentials, CertificateAuth
# 1. Setup Credentials
credentials = OAuthCredentials(
client_id="your_client_id",
client_secret="your_client_secret",
app_key="bb_key" # If using Banco do Brasil
)
# 2. Setup Certificates
cert_auth = CertificateAuth(
cert_path="/path/to/cert.pem",
key_path="/path/to/key.pem"
)
# 3. Generate Adapter (Factory)
adapter = BankSlipManager.get_adapter(
bank="bb",
credentials=credentials,
environment="sandbox",
cert_auth=cert_auth
)
# 4. Call the desired feature
payload_boleto = { ... } # Your JSON dictionary matching the bank's schema
response = adapter.generate_bank_slip(payload_boleto)
print(response)
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pybank_slip-0.1.0.tar.gz.
File metadata
- Download URL: pybank_slip-0.1.0.tar.gz
- Upload date:
- Size: 8.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0cc486ea5f96b046a4c1ad6bf98eff61a81a1789c0cde7318fa5441781f3fc09
|
|
| MD5 |
407df7f0c2a72e6566d0b296b65e0c59
|
|
| BLAKE2b-256 |
58ff3f24029ea0771407e118b099bd6e927c076af09683445232efdcfc23865a
|
File details
Details for the file pybank_slip-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pybank_slip-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
29c0bdb32336026ed7d42c1a999fdd2ee7c8a196408909a10ed9b66c3b419bd1
|
|
| MD5 |
4cb13e45fbc3f39008e86eafdf7577d9
|
|
| BLAKE2b-256 |
16b4da5644a05f0c97c15c1f5be6902b6181477b5195eff7466dd157e1be25f2
|