Skip to content

Python SDK

feitpay has no third-party dependencies (it uses urllib, hmac and json).

Terminal window
pip install feitpay # once published; in the monorepo use sdk/python directly
import os
from feitpay import FeitPay, FeitPayError, NotFoundError
gp = FeitPay(api_key=os.environ["FEITPAY_API_KEY"], base_url="https://api.feitpay.com", timeout=30, max_retries=2)
intent = gp.payment_intents.create(
store_id="store_YOUR_STORE_ID", amount="59.90", currency="EUR",
merchant_order_id="order-123", idempotency_key="order-123",
)
for pi in gp.payment_intents.list_all(status=["confirmed", "overpaid"]):
print(pi["id"], pi["fulfillable"])
try:
gp.invoices.retrieve("inv_missing")
except NotFoundError as exc:
print(exc.code, exc.request_id)

Resources: payment_intents, checkout_sessions, invoices, payment_links, transactions, wallets, stores, webhook_endpoints, webhook_deliveries, events, reports, billing, pix, platform. Responses are plain dicts mirroring the API; amounts stay strings. format_base_units("99834", 8) formats exactly.

Retries follow the same rules as the other SDKs (GET and keyed POST; network errors, 429, 5xx; jittered exponential backoff honouring Retry-After).

Pass allowed_methods on a payment in BRL: ["pix"] makes a PIX-only payment, and ["crypto", "pix"] lets the customer choose at checkout. Payment intents, invoices and payment links take the same field; leave it out for crypto only.

# A PIX-only payment.
pix_only = gp.payment_intents.create(
store_id="store_YOUR_STORE_ID", amount="59.90", currency="BRL",
allowed_methods=["pix"], idempotency_key="order-1042",
)
# The customer chooses crypto or PIX at checkout.
either = gp.payment_intents.create(
store_id="store_YOUR_STORE_ID", amount="59.90", currency="BRL",
allowed_methods=["crypto", "pix"], idempotency_key="order-1043",
)

Read fees, minimums and availability from the API instead of hard-coding them. gp.pix.pricing() calls GET /v1/pix/pricing (API keys need the balances:read scope):

pricing = gp.pix.pricing()
if not pricing["available"]:
... # PIX is switched off: create crypto-only payments

pricing["tiers"] (in order; the first tier whose bound holds applies), minimum_fee, minimum_payment and payout_fee are BRL decimal strings. Once the PIX charge is open, processor["methods"][i]["pix_copy_paste"] on the payment intent is its copia e cola code; once the payment is credited, processor["fee"] is the PIX fee that was deducted. Checkout, statuses, fees and error codes: PIX (Brazil).

from feitpay import webhooks
from feitpay.webhooks import WebhookVerificationError
try:
event = webhooks.verify(raw_body, headers["FeitPay-Signature"], [new_secret, old_secret])
except WebhookVerificationError as exc:
respond(400, {"error": exc.reason})

Run the tests from sdk/python: python -I -m unittest discover -s tests -t .