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.0
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 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.

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.0

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.0
File Size Uploaded
commercexl-0.3.0.tar.gz 73.3 kB Details

Built distribution (wheel)

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

Total release size: 166.9 kB

Release files / commercexl-0.3.0.tar.gz

Download URL commercexl-0.3.0.tar.gz
Size 73.3 kB
Tags Source
SHA-256 checksum
How to use checksums
54fc772b5c23cf5761ee13fe402a7e86c6260c6ffd79c8e0d30387027523b185
BLAKE2b-256 checksum
How to use checksums
0f6cc30b9b398f54b74bc2a726b8ecedf02f964a3bc89551be044b03d7eff1b5
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.0-py3-none-any.whl

Download URL commercexl-0.3.0-py3-none-any.whl
Size 93.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ab1ac72f6c548e0d3ac962a563b6918fe77ea8714e2f4c1d6aebd2402f1c57b0
BLAKE2b-256 checksum
How to use checksums
64195295cd5fd56fd7904a149f3f3d086017d07661ff1a55082323d46cda62e1
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

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

This release

0.3.0 This release

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