Skip to main content

Composable commerce core for products, order items, and payments.

Project description

commercexl

commercexl is a reusable commerce core for:

  • product catalog records
  • checkout orders
  • order items
  • payment systems
  • FastAPI router assembly

It does not create your DB engine, session factory, auth, or project-specific payment callbacks.

Installation

pip install commercexl

For tests and local development:

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

What the library gives you

  • SQLAlchemy models via CommerceBase
  • explicit module wiring via CommerceModule
  • abstract services for products, order items, and payments
  • built-in balance and handmade payments
  • FastAPI router factory via create_router(...)

Quick start

from decimal import Decimal

from commercexl import (
    BaseConfig,
    CommerceModule,
    DefaultOrderItemService,
    HandMadePaymentService,
    PaymentConfigBuilder,
    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(HandMadePaymentService),
)

FastAPI integration

from commercexl import CommerceHTTPConfig, CommerceUserActorDTO, create_router

app.include_router(
    create_router(
        CommerceHTTPConfig(
            get_db_session_dependency=get_db_session,
            get_current_user_dependency=get_current_user,
            get_commerce_module=lambda: commerce,
            build_actor=lambda user: CommerceUserActorDTO(id=user.id),
            get_user_id=lambda user: int(user.id),
            is_staff=lambda user: bool(user.is_staff),
        ),
    ),
    prefix="/api/v1",
)

Alembic

commercexl does not ship migrations. The host project owns migrations.

Add library metadata to your Alembic target_metadata:

from commercexl import CommerceBase
from my_project.db import Base

target_metadata = [
    Base.metadata,
    CommerceBase.metadata,
]

Docs

Testing

pytest

Project details


Download files

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

Source Distribution

commercexl-0.1.2.tar.gz (40.6 kB view details)

Uploaded Source

Built Distribution

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

commercexl-0.1.2-py3-none-any.whl (62.9 kB view details)

Uploaded Python 3

File details

Details for the file commercexl-0.1.2.tar.gz.

File metadata

  • Download URL: commercexl-0.1.2.tar.gz
  • Upload date:
  • Size: 40.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for commercexl-0.1.2.tar.gz
Algorithm Hash digest
SHA256 354373f876a5e0ee1f0a87f3205c8f172779550f17759b07472616122a3b4e8b
MD5 3bf78e20ad4967a2a1714224db3ef01d
BLAKE2b-256 e7a9e51da9bff8e2ba8729484c252c74b0b80b3eca73bc4e27b55001ab2c2452

See more details on using hashes here.

Provenance

The following attestation bundles were made for commercexl-0.1.2.tar.gz:

Publisher: ci.yml on Artasov/commercexl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file commercexl-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: commercexl-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 62.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for commercexl-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 24196254c00b6fa9accdf3ac72cad8fd1a808a281707edce330f0c824ccbc912
MD5 2cf4a62c50796281b2f9921b1ed17f79
BLAKE2b-256 c7382dcff5a4743aa6c8f797735ab8c241ec52b4cc71e331eadef10a8489763a

See more details on using hashes here.

Provenance

The following attestation bundles were made for commercexl-0.1.2-py3-none-any.whl:

Publisher: ci.yml on Artasov/commercexl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page