Skip to main content

Official Python SDK for Loyalty.lt Shop API

Project description

Loyalty.lt Python SDK

Official Python SDK for Loyalty.lt Shop 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 API Key
api_secret str required 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='123-456-789')

# 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'
)

# 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.get_loyalty_card_info(card_number='INVALID')
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.3.tar.gz (11.1 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.3-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: loyaltylt_sdk-1.0.3.tar.gz
  • Upload date:
  • Size: 11.1 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.3.tar.gz
Algorithm Hash digest
SHA256 c0c53162854e621fdacd3a6497e7a0d25f57ce236796076c26a675b2e1ec2658
MD5 bceb72a78cf16dda1c0d5b1aab830285
BLAKE2b-256 d184490b8ab9b2322781ed4711148e6498195832cfe7b47000567a85c938577c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: loyaltylt_sdk-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 10.1 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9606c7b3fcc6a833008d428d6c9559d3800252453de19ce37f30dd3c6e636e55
MD5 4ac047cfae4e8519c2191886c46691e7
BLAKE2b-256 b3f143a697015b5236798233839c617ddbb7dcd3988833afd69c79356d89d5a8

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