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

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

Built distribution (wheel)

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

Total release size: 167.0 kB

Release files / commercexl-0.3.1.tar.gz

Download URL commercexl-0.3.1.tar.gz
Size 73.3 kB
Tags Source
SHA-256 checksum
How to use checksums
411b064680a36b7ab05d55face28fa108424e19c4cfda53f420218d812f55c9c
BLAKE2b-256 checksum
How to use checksums
3a1b38f9aafd078a84596de9cb0adb9a946ad72419fb752745fa060dae9ff6a0
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.1-py3-none-any.whl

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

This release

0.3.1 This release

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