Skip to main content

Python SDK and CLI for interacting with the Villa Market backend server

Project description

Villa Market Backend SDK

Python SDK and CLI for the Villa Market backend: Cognito authentication, order building, validation, and card payment.

User Manual (hosted)

Read the full manual on S3

The manual covers installation, Cognito login/SignUp, order building, pre-payment validation, card payment, CLI commands, environment variables, and troubleshooting. It is rebuilt and deployed to S3 automatically when docs change on main.


Quick start

1. Install

pip install villa-market-backend-sdk

Python import: from villa_backend_sdk import VillaClient

2. Configure Cognito

cp .env.example .env
# Set VILLA_COGNITO_CLIENT_SECRET from Cognito → Show client secret
set -a && source .env && set +a
Variable Description
VILLA_COGNITO_CLIENT_ID Cognito app client ID
VILLA_COGNITO_USER_POOL_ID Cognito user pool ID
VILLA_COGNITO_CLIENT_SECRET App client secret
VILLA_COGNITO_REGION AWS region (default ap-southeast-1)

3. Login and call APIs

from villa_backend_sdk import VillaClient, OrderBuilder

client = VillaClient.from_env()
client.login("user@example.com", "password")  # attaches JWT to all requests

order = (
    OrderBuilder()
    .with_ids(order_id="order-1", owner_id="owner-1", basket_id="basket-1")
    .with_branch("1000")
    .add_product(cprcode=25281, quantity=1)
    .with_payment_totals(grand_total=174.0)
    .build()
)

result = client.pre_payment.validate(order, expected_grand_total=174.0)
print(result.valid)

Verify login:

python3 scripts/smoke_test_cognito_login.py

CLI

villa auth login --username user@example.com --password 'secret'
villa health
villa order validate-schema --file tests/fixtures/goodSample.json
villa validate pre-payment --file tests/fixtures/goodSample.json --expected-grand-total 500

See the manual for the full CLI reference.


Documentation

Document Contents
Manual (S3) Complete usage guide
docs/MANUAL.md Manual source (repo)
docs/DESIGN.md Architecture and data flow
docs/TESTING.md Test strategy
docs/COGNITO_TEST.md Shared test account
docs/CI_CD.md CI/CD and deployment

Development

git clone https://github.com/villa-market/villa-backend-sdk-1.git
cd villa-backend-sdk-1
pip install -e ".[dev]"
set -a && source .env && set +a
pytest
Suite Command
Unit pytest tests/unit -m unit
Integration (real Cognito JWT) pytest tests/integration -m integration
Full pytest (72 tests)

Build and deploy the manual locally:

python3 scripts/build_manual_site.py
python3 scripts/deploy_manual_s3.py

Architecture

Module Responsibility
villa_backend_sdk.auth Cognito login, SignUp, confirm
villa_backend_sdk.orders Order builder, create/get/generate ID
villa_backend_sdk.validation Schema + remote pricing validation
villa_backend_sdk.payments Card token, card payment, verify
villa_backend_sdk.cli villa command-line tool

License

MIT

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

villa_market_backend_sdk-0.2.1.tar.gz (26.2 kB view details)

Uploaded Source

Built Distribution

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

villa_market_backend_sdk-0.2.1-py3-none-any.whl (34.4 kB view details)

Uploaded Python 3

File details

Details for the file villa_market_backend_sdk-0.2.1.tar.gz.

File metadata

  • Download URL: villa_market_backend_sdk-0.2.1.tar.gz
  • Upload date:
  • Size: 26.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for villa_market_backend_sdk-0.2.1.tar.gz
Algorithm Hash digest
SHA256 ae6e0acc92820dea6707bdd3468bfd2f207bf3fe781c73c6dd7ec230f8547bcf
MD5 e0427804b330630b8c516ac41a86b57b
BLAKE2b-256 178113a640f482b494928fb10f21670a6768741b6b6bc1557b43381437302190

See more details on using hashes here.

File details

Details for the file villa_market_backend_sdk-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for villa_market_backend_sdk-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cfd19c8552763b52eb37c20c6a2d75341f965eb7973cf32eb6c42ad33198fa2c
MD5 f0c4af4b2a8b8c6c1e61494abc6974a5
BLAKE2b-256 a38aa768941a167de524890a83e882f781e747efcdf64b4ca421e309c39d4c6c

See more details on using hashes here.

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