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='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.2.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.2-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: loyaltylt_sdk-1.0.2.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.2.tar.gz
Algorithm Hash digest
SHA256 b8dfaf989f17c61a2eda7618a52329bc4965af4fed70d2830dc7bc9acece92f8
MD5 818bec84636b32edbf9fc667fa0bf631
BLAKE2b-256 786ec117f830c02020c90dcf8bee31a41a23015002b614d61ef8ade323ffbb44

See more details on using hashes here.

File details

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

File metadata

  • Download URL: loyaltylt_sdk-1.0.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 df9700acabb5df5f479f3363491595c72a3426311b19c04e894668bee0f329bc
MD5 b6a08ba7d9e965407139a8e9209b24d9
BLAKE2b-256 0f3a930b1d8bd0e11aeb1b7cc2a787dd7962a03476bafd62b85bd69b61a84747

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