Skip to main content

fawaterak

Unofficial Python SDK for the Fawaterak API.

This project is not affiliated with, endorsed by, or sponsored by Fawaterak. It is a community-maintained, unofficial SDK written by independent developers. The maintainers have no business relationship with the company Fawaterak. Use this library at your own risk.

Status

This project is in early development (0.3.1). The foundational OAuth/HTTP layers, the core transaction client (payment methods, create/fetch/list transactions), and the framework-agnostic webhook verification/parsers are implemented. E-invoicing, refunds, and tokenization are still on the roadmap.

Features

  • Explicit configuration via constructor arguments or environment variables.
  • OAuth2 token management (client_credentials + refresh_token flows) with automatic caching and expiry-aware renewal.
  • Thread-safe token refresh so concurrent callers do not issue duplicate /oauth/token requests.
  • Central HTTP client with bearer-token injection, transport-level retries, and Fawaterak-specific error mapping.
  • Exception hierarchy for network, authentication, validation, and transient API errors.
  • FawaterakClient with get_payment_methods, create_transaction, get_transaction, and list_transactions covering the core transaction flow.
  • Webhook verification and parsing with HMAC signature checks and typed event dataclasses (PaidWebhookEvent, FailedWebhookEvent, CancelWebhookEvent, RefundWebhookEvent).
  • Two transaction modes — hosted checkout (result.url) and direct payment (result.payment_data), with a discriminated PaymentResult union for card redirects, reference codes (Fawry/Aman/Masary), and mobile wallets.
  • Typed dataclass models (Customer, CartItem, TransactionData, Page, etc.) that serialize to the exact API payload shapes.

Installation

pip install fawaterak

Or with uv:

uv add fawaterak

Quick start

from fawaterak import Config, FawaterakClient

conf = Config.resolve(
	client_id="your-client-id",
	client_secret="your-client-secret",
	environment="staging",  # or "production"
)

client = FawaterakClient(config=conf)
methods = client.get_payment_methods()
print([method.name_en for method in methods])

Configuration

Config.resolve() accepts explicit arguments and falls back to environment variables. Explicit arguments always win.

Setting Environment variable Required
client_id FAWATERAK_CLIENT_ID Yes
client_secret FAWATERAK_CLIENT_SECRET Yes
environment FAWATERAK_ENV Yes*
base_url Yes*
vendor_api_key FAWATERAK_VENDOR_API_KEY No**

* Either environment (staging or production) or a direct base_url must be provided.

** Must be provided if you plan to use Webhooks.

Usage

Hosted checkout

Omit payment_method_id to create a payment link and redirect the customer to the Fawaterak-hosted checkout page.

from fawaterak import CartItem, Customer, RedirectionUrls

result = client.create_transaction(
	currency="EGP",
	customer=Customer(
		first_name="Ahmed",
		last_name="Ali",
		email="ahmed@example.com",
	),
	cart_items=[CartItem(name="Order total", price=100.0, quantity=1)],
	cart_total=100.0,
	redirection_urls=RedirectionUrls(
		success_url="https://yoursite.com/success",
		fail_url="https://yoursite.com/fail",
	),
)

# result is a HostedCheckoutResult
redirect_url = result.url

Direct payment

Pass a payment_method_id from get_payment_methods() to pay with a specific method. The response returns provider-specific data in result.payment_data.

result = client.create_transaction(
	currency="EGP",
	customer=Customer(first_name="Ahmed", last_name="Ali"),
	cart_items=[CartItem(name="Order total", price=100.0, quantity=1)],
	cart_total=100.0,
	payment_method_id=3,  # e.g. Fawry
)

from fawaterak import (
	CardPaymentResult,
	MobileWalletResult,
	ReferenceCodeResult,
)

payment = result.payment_data
if isinstance(payment, ReferenceCodeResult):
	print(payment.reference_number)
elif isinstance(payment, CardPaymentResult):
	print(payment.redirect_to)
elif isinstance(payment, MobileWalletResult):
	print(payment.iso_qr)

Fetch and list transactions

from datetime import date

transaction = client.get_transaction("550e8400-e29b-41d4-a716-446655440000")
print(transaction.status_text)

page = client.list_transactions(
	start_date=date(2026, 1, 1),
	end_date=date(2026, 1, 31),
	per_page=15,
)
for item in page.data:
	print(item.transaction_id, item.status_text)

Webhooks

The SDK verifies webhook HMAC signatures using your vendor API key (not the OAuth client secret). It is framework-agnostic: parse the incoming body into a dict using your web framework, then call the provided parser.

Flask example (paid webhook)

from fawaterak import FawaterakClient

client = FawaterakClient()


@app.post("/webhooks/fawaterak/paid/")
def handle_paid_webhook():
	payload = request.get_json() or request.form.to_dict()
	event = client.parse_paid_webhook(payload)

	if event.status == "paid":
		fulfill_order(event)

	return "OK", 200

Django example

from django.http import JsonResponse
from django.views.decorators.csrf import csrf_exempt
from fawaterak import FawaterakClient

client = FawaterakClient()


@csrf_exempt
def fawaterak_paid_webhook(request):
	payload = request.POST if request.method == "POST" else request.json()
	event = client.parse_paid_webhook(payload)

	if event.status == "paid":
		fulfill_order(event)

	return JsonResponse({"status": "ok"})

FastAPI example

from fastapi import FastAPI, Request
from fawaterak import FawaterakClient

app = FastAPI()
client = FawaterakClient()


@app.post("/webhooks/fawaterak/paid/")
async def handle_paid_webhook(request: Request):
	payload = await request.json()
	event = client.parse_paid_webhook(payload)

	if event.status == "paid":
		fulfill_order(event)

	return {"status": "ok"}

Other webhook types

# Failed payment
failed_event = client.parse_failed_webhook(payload)

# Cancelled / expired reference
cancel_event = client.parse_cancel_webhook(payload)

# Refund approved
refund_event = client.parse_refund_webhook(payload)

# Dispatch by type when the endpoint handles multiple webhook kinds
from fawaterak.webhooks import WebhookType

event = client.parse_webhook(payload, WebhookType.REFUND)

You can also call the standalone functions in fawaterak.webhooks directly if you prefer not to instantiate FawaterakClient for webhook handlers.

Paid and failed webhooks can be delivered as JSON or form-urlencoded; cancel and refund webhooks are always JSON. The parsers raise FawaterakWebhookException if the signature does not match. The generic verify_webhook/parse_webhook dispatchers raise FawaterakWebhookException for unknown webhook types.

Development

This project uses uv for dependency management.

# Install dependencies
uv sync --all-extras --dev

# Run tests
uv run pytest

# Run live integration tests against staging (requires real credentials)
uv run pytest -m integration

# Run linters and type checker
uv run ruff check .
uv run ruff format --check .
uv run ty check .

License

This project is licensed under the GNU Affero General Public License v3.0 or later (AGPL-3.0+). See LICENSE for the full text.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fawaterak-0.3.1.tar.gz (45.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fawaterak-0.3.1-py3-none-any.whl (52.9 kB view details)

Uploaded Python 3

File details

Details for the file fawaterak-0.3.1.tar.gz.

File metadata

  • Download URL: fawaterak-0.3.1.tar.gz
  • Upload date:
  • Size: 45.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for fawaterak-0.3.1.tar.gz
Algorithm Hash digest
SHA256 0b2e6fd9ec37f2d17a7180bbbe3303b883ebd668548bfe989e71459bb4c3119d
MD5 eb4d69d5f5c758efbd7abc9878b19016
BLAKE2b-256 d4bfa6c20bd1f4a3d5596a0621fcc76fa8cac4251c712aa92fc48a2dcf47700c

See more details on using hashes here.

File details

Details for the file fawaterak-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: fawaterak-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 52.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for fawaterak-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e6508d82571be196d7d4d0f990a00b9cfb1f356a90661e373f2ccb12a83e0ada
MD5 bcacc0607bf6024a03a3282a16fafd9a
BLAKE2b-256 ab6b9fc8c27291661a9899b7a8ef9a882efe8c9eb68b81e7520f06aeaa9d10da

See more details on using hashes here.

Release history Release notifications | RSS feed

0.4.0

2 files

This release

0.3.1 This release

2 files

0.3.0

2 files

0.2.0

2 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