Skip to main content

Official Python SDK for Loyalty.lt Partner API

Project description

Loyalty.lt Python SDK

Official Python SDK for Loyalty.lt Partner API.

PyPI version Python Version License

Installation

pip install loyaltylt-sdk

Requirements

  • Python 3.8+
  • requests

Quick Start

from loyalty_sdk import LoyaltySDK

sdk = LoyaltySDK(
    api_key='lty_your_api_key',
    api_secret='your_api_secret',
    environment='production',  # or 'staging'
    locale='lt'
)

# Get shops
shops = sdk.get_shops()
print(shops['data'])

Configuration Options

Option Type Default Description
api_key str required Partner API Key
api_secret str required Partner API Secret
environment str production production or staging
locale str lt API locale (lt, en)
timeout int 30 Request timeout in seconds
retries int 3 Number of retry attempts
debug bool False Enable debug logging

Features

QR Login

# Generate QR login session
session = sdk.generate_qr_login('POS Terminal #1', shop_id=1)

print(session['session_id'])
print(session['qr_code'])  # Deep link for QR code
print(session['expires_at'])

# Poll for status
status = sdk.poll_qr_login(session['session_id'])

if status['status'] == 'authenticated':
    user = status['user']
    print(f"Welcome, {user['name']}")

QR Card Scan (POS Customer Identification)

# Generate QR card scan session
session = sdk.generate_qr_card_session('POS Terminal')

# Poll for customer identification
result = sdk.poll_qr_card_status(session['session_id'])

if result['status'] == 'completed':
    card = result['card_data']
    print(f"Customer: {card['user']['name']}")
    print(f"Points: {card['points_balance']}")

Real-time Updates with Ably

# Get Ably token
ably_token = sdk.get_ably_token(session['session_id'])

# Use with Ably client
print(ably_token['token'])
print(ably_token['channel'])

Shops

# Get all shops
shops = sdk.get_shops()

# Filter shops
shops = sdk.get_shops(is_active=True, is_virtual=False)

Loyalty Cards

# Get cards
cards = sdk.get_loyalty_cards()

# Get single card
card = sdk.get_loyalty_card(123)

# Get card by number
card_info = sdk.get_loyalty_card_info(card_number='LOYALTY123456')

# Get points balance
balance = sdk.get_points_balance(card_id=123)

Transactions & Points

# Award points
transaction = sdk.create_transaction(
    card_id=123,
    amount=50.00,
    points=50,
    transaction_type='earn',
    description='Purchase reward',
    reference='ORDER-12345'
)

# Deduct points
sdk.deduct_points(card_id=123, points=100, description='Points redemption')

# Get transactions
transactions = sdk.get_transactions(card_id=123, type='earn')

Offers

# Get offers
offers = sdk.get_offers(is_active=True)

# Create offer
offer = sdk.create_offer(
    title='Summer Sale',
    description='20% off all items',
    discount_type='percentage',
    discount_value=20,
    start_date='2024-06-01',
    end_date='2024-08-31'
)

# Get categories
categories = sdk.get_categories()

XML Import

# Import offers from XML
result = sdk.import_from_url(
    'https://example.com/offers.xml',
    auto_publish=True
)

# Validate XML
validation = sdk.validate_xml('https://example.com/offers.xml')

# Get import stats
stats = sdk.get_import_stats()

Error Handling

from loyalty_sdk import LoyaltySDKError, LoyaltyAPIError

try:
    result = sdk.deduct_points(card_id=123, points=10000)
except LoyaltyAPIError as e:
    print(f"Error: {e.message}")
    print(f"Code: {e.code}")
    print(f"HTTP Status: {e.http_status}")
except LoyaltySDKError as e:
    print(f"SDK Error: {e}")

Django Integration

# settings.py
LOYALTY_API_KEY = os.environ.get('LOYALTY_API_KEY')
LOYALTY_API_SECRET = os.environ.get('LOYALTY_API_SECRET')

# services.py
from loyalty_sdk import LoyaltySDK
from django.conf import settings

def get_loyalty_sdk():
    return LoyaltySDK(
        api_key=settings.LOYALTY_API_KEY,
        api_secret=settings.LOYALTY_API_SECRET
    )

# views.py
from .services import get_loyalty_sdk

def award_points(request):
    sdk = get_loyalty_sdk()
    transaction = sdk.create_transaction(
        card_id=request.POST['card_id'],
        amount=request.POST['amount'],
        points=int(request.POST['amount'])
    )
    return JsonResponse(transaction)

Flask Integration

from flask import Flask, jsonify, request
from loyalty_sdk import LoyaltySDK
import os

app = Flask(__name__)

sdk = LoyaltySDK(
    api_key=os.environ['LOYALTY_API_KEY'],
    api_secret=os.environ['LOYALTY_API_SECRET']
)

@app.route('/award-points', methods=['POST'])
def award_points():
    data = request.json
    transaction = sdk.create_transaction(
        card_id=data['card_id'],
        amount=data['amount'],
        points=data['points']
    )
    return jsonify(transaction)

API Documentation

Full API documentation: docs.loyalty.lt

Support

License

MIT License - see LICENSE for details.

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

loyaltylt_sdk-1.0.0.tar.gz (11.2 kB view details)

Uploaded Source

Built Distribution

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

loyaltylt_sdk-1.0.0-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file loyaltylt_sdk-1.0.0.tar.gz.

File metadata

  • Download URL: loyaltylt_sdk-1.0.0.tar.gz
  • Upload date:
  • Size: 11.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for loyaltylt_sdk-1.0.0.tar.gz
Algorithm Hash digest
SHA256 145e4b3262f7505ec8c2ab556e3a770abb03b3262b3cc00e6cad3c71a7398f7a
MD5 723c6fee61630a35b4c266770665cc07
BLAKE2b-256 0ff33acf498002c6f9fa823b8fcfea87437e3c033b12f77ac8ec1c3fa2c84eb6

See more details on using hashes here.

File details

Details for the file loyaltylt_sdk-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: loyaltylt_sdk-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for loyaltylt_sdk-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9428eac8b1500300f3a0ac565ffacf2a679d4b53a0d7df5ebd756a3018a6d9ec
MD5 b6c95a6ebbc365b19e56ea4b1415dc28
BLAKE2b-256 9ad33afcbda49ae433e9bb47184dfb2a6f6cbe55be76080232737f317e7eddb2

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