Skip to main content

English · Русский

CommerceXL banner

CommerceXL

PyPI CI License: MPL 2.0

Composable commerce backend foundation for the Orcestr ecosystem.

CommerceXL provides reusable catalog, order, balance and payment primitives for FastAPI, Pydantic 2 and SQLAlchemy 2 applications. The host application owns the database engine, sessions, users, authentication, CSRF policy, migrations and provider-specific callback routes.

Status

Item Value
Package commercexl
Version 0.3.3
Status Beta, breaking from 0.2
Runtime Python 3.12+
Frameworks FastAPI, SQLAlchemy 2, Pydantic 2

What Is Included

Area Includes
Catalog products, exact decimal prices and extensible product services
Orders multi-item orders with canonical order and item states
Payments canonical payment attempts, strict provider registry and typed checkout actions
Lifecycle idempotent create, verification, cancellation, refund and exact-once product finalization
Balances internal credit balances and currency conversion settings
Promotions promocodes and gift-certificate foundations
Events transactional payment outbox and globally unique provider evidence claims
HTTP auth-neutral FastAPI router assembled through create_router(...)
Persistence typed SQLAlchemy models exposed through CommerceBase

CommerceXL does not include a frontend, wallet integration, blockchain verifier or payment-provider credentials. Those belong in separate provider packages and host adapters.

Installation

pip install commercexl

Optional development dependencies:

pip install "commercexl[test]"
pip install "commercexl[dev]"

Quick Start

from decimal import Decimal

from commercexl import (
    BaseConfig,
    CommerceModule,
    DefaultOrderItemService,
    HandMadePaymentService,
    PaymentConfigBuilder,
    PaymentProviderRegistration,
    ProductOrderConfig,
    ProductOrderConfigBuilder,
)


class ProjectCommerceConfig(BaseConfig):
    PAYMENT_SYSTEMS = {"USD": ("handmade",)}
    MIN_TOP_UP_AMOUNTS = {"USD": Decimal("1")}
    CREDITS_CONVERTERS = {"USD": Decimal("10000")}


commerce = CommerceModule(
    config_class=ProjectCommerceConfig,
    product_orders=ProductOrderConfigBuilder(
        ProductOrderConfig(MyProductService, DefaultOrderItemService),
    ),
    payments=PaymentConfigBuilder(
        PaymentProviderRegistration(
            system="handmade",
            provider_kind="handmade",
            factory=HandMadePaymentService,
        ),
    ),
    public_base_url="https://commerce.example.com",
)

Provider registration is strict. A duplicate normalized system, a missing provider referenced by PAYMENT_SYSTEMS, or a factory returning the wrong service type fails during module construction.

FastAPI Integration

The host supplies an authenticated actor dependency and a mandatory mutation guard. For cookie-authenticated applications, the mutation guard is the host CSRF dependency.

from fastapi import Depends
from commercexl import CommerceHTTPConfig, CommerceUserActorDTO, create_router


async def get_commerce_actor(user=Depends(get_current_user)) -> CommerceUserActorDTO:
    return CommerceUserActorDTO(id=user.id, permissions=frozenset(user.permissions))


app.include_router(
    create_router(
        CommerceHTTPConfig(
            get_db_session_dependency=get_db_session,
            get_current_actor_dependency=get_commerce_actor,
            get_mutation_guard_dependency=check_csrf,
            get_commerce_module=lambda: commerce,
        ),
    ),
    prefix="/api/v1",
)

The optional filter_public_products hook receives the active AsyncSession and the already serialized list[ProductDTO]. It applies only to GET /products/, allowing a host to keep tenant-bound or otherwise host-orchestrated products out of the generic public catalog without changing CommerceXL product storage:

async def filter_public_products(session, products):
    hidden_kinds = await host_catalog.get_orchestrated_product_kinds(session)
    return [product for product in products if product.kind not in hidden_kinds]


CommerceHTTPConfig(
    # ...required dependencies...
    filter_public_products=filter_public_products,
)

With the default None, the endpoint returns the full serialized CommerceXL catalog as before. The hook does not affect internal serializers, balance-product lookup, gift certificates or order creation; hosts must still enforce checkout authorization independently.

The checkout is intentionally two-phase:

  1. POST /orders/ creates a server-priced order and requires Idempotency-Key.
  2. GET /orders/{order_id}/payment-options/ returns options available to that actor and order.
  3. POST /orders/{order_id}/payment-attempts/ accepts only payment_option_id and another Idempotency-Key.
  4. GET /payments/{payment_public_id}/ returns authoritative state without issuing a secret.
  5. POST /payments/{payment_public_id}/checkout-action/ issues a fresh provider action.

Amounts are Decimal in Python and decimal strings in JSON. The client cannot submit the final payment amount, commercial currency or arbitrary provider system when creating an attempt. Each PaymentOptionDTO repeats the authoritative order-snapshot amount and currency, so a catalog price change after order creation cannot change the amount shown or paid for that order. Currency codes are host-defined strings (for example, fiat or application tokens), not a closed CommerceXL enum.

Provider Contract

Provider packages implement AbstractPaymentService or AbstractCallbackPaymentService and are registered through PaymentProviderRegistration. The stable provider-facing imports include PaymentCreateContext, PaymentCreateResult, PaymentOption, CheckoutAction, PaymentVerificationResult and PaymentState.

The canonical PaymentORM is the extension root for provider child tables. Providers do not mutate orders or mark them paid directly. A trusted callback/reconciliation adapter returns a typed verification result and passes it to PaymentRuntime.apply_verification(...) in the current DB session.

Checkout capability URLs and transaction-request bearer values must be issued by get_action(...); CommerceXL persists only non-secret action metadata. Safe provider evidence is claimed globally and payment changes write PaymentOutboxEventORM in the same transaction.

Database Migrations

CommerceXL does not ship application migrations. Add its metadata to the host Alembic setup and generate/review migrations in the host repository:

from commercexl import CommerceBase
from my_project.db import Base

target_metadata = [Base.metadata, CommerceBase.metadata]

Version 0.3 is a deliberate breaking schema/API release. Follow the 0.2 to 0.3 migration guide before upgrading production data.

Documentation

Development

uv sync --all-extras
uv run pytest -q
uv build

License

Licensed under the Mozilla Public License 2.0. Commercial use is permitted; changes to MPL-covered files remain subject to the MPL. See NOTICE and TRADEMARKS.md.

Orcestr Ecosystem

Release files for commercexl 0.3.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for commercexl 0.3.3
File Size Uploaded
commercexl-0.3.3.tar.gz 76.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for commercexl 0.3.3
File Interpreter ABI Platform
commercexl-0.3.3-py3-none-any.whl Python 3 none any Details

Total release size: 171.4 kB

Release files / commercexl-0.3.3.tar.gz

Download URL commercexl-0.3.3.tar.gz
Size 76.7 kB
Tags Source
SHA-256 checksum
How to use checksums
58db1bf2a4e163f941de721221440441000054a56fa0faf9e9c652f0a88b6d74
BLAKE2b-256 checksum
How to use checksums
f680e50ff1eeb27f51e1b0e1cb93e5cca412ab01d8f1f9cbe608f6be92f00fb1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 31, 2026.

Transparency log

Release files / commercexl-0.3.3-py3-none-any.whl

Download URL commercexl-0.3.3-py3-none-any.whl
Size 94.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
db6ca32693c3e0e69a02484b1117c97935543a3faee728b791ddbef126365559
BLAKE2b-256 checksum
How to use checksums
5b1144efafa6b6cbfa6fb08e2f92d61ed3e8e5d3dcd90d7118712d9d24fb8d18
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 31, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.3.3 This release

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release 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