Skip to main content

Unofficial Python wrapper for SOK / S-Kaupat APIs

Project description

sokpy

A Python wrapper for the SOK (S-Group) API, providing easy access to store information, product data, and pricing from Finnish S-Group stores.

Features

  • Store Management: Retrieve information about S-Group stores by brand or location
  • Product Information: Get detailed product data including pricing, availability, and specifications
  • Pricing Data: Access current prices, campaign prices, and historical pricing information
  • Category Browsing: Browse products by categories within specific stores

Installation

pip install sokpy

Quick Start

from sokpy import SOKAPI

# Initialize the API
api = SOKAPI()

# Get a product by ID
product = api.get_product_by_id("some-product-id")
print(f"Product: {product.name}")
print(f"Price: {product.price} €")

# Get stores by brand
stores = api.get_stores_by_brand("S-Market")
for store in stores[:5]:  # Show first 5 stores
    print(f"Store: {store.name} - {store.location}")

# Get a specific store
store = api.get_store_by_id("some-store-id")
print(f"Store: {store.name}")
print(f"Opening hours: {store.weeklyOpeningHours}")

API Reference

SOKAPI

The main API class for interacting with SOK services.

Methods

  • get_product_by_id(product_id: str) -> SOKProduct: Retrieve a product by its ID
  • get_all_stores() -> dict: Get all stores organized by brand
  • get_stores_by_brand(brand: str) -> list[SOKStore]: Get stores for a specific brand
  • get_store_by_id(store_id: str) -> SOKStore: Get a specific store by ID

SOKProduct

Represents a product with detailed information.

Attributes

  • product_id: Unique product identifier
  • sokId: SOK-specific product ID
  • name: Product name
  • price: Current price
  • availability: Product availability status
  • pricing: SOKPricing object with detailed pricing information
  • basicQuantityUnit: Unit of measurement
  • comparisonPrice: Price per comparison unit
  • comparisonUnit: Unit for price comparison
  • priceUnit: Unit for pricing
  • isAgeLimitedByAlcohol: Whether the product is age-restricted
  • frozen: Whether the product is frozen
  • packagingLabelCodes: List of packaging label codes
  • brandName: Brand name
  • packagingLabels: List of packaging labels
  • slug: URL slug for the product

SOKPricing

Contains detailed pricing information for a product.

Attributes

  • campaignPrice: Current campaign price
  • lowest30DayPrice: Lowest price in the last 30 days
  • campaignPriceValidUntil: Campaign validity date
  • regularPrice: Regular price
  • currentPrice: Current price
  • salesUnit: Unit for sales
  • comparisonPrice: Price for comparison
  • comparisonUnit: Unit for comparison
  • isApproximatePrice: Whether price is approximate
  • depositPrice: Deposit price
  • quantityMultiplier: Quantity multiplier

SOKStore

Represents a store with location and product information.

Attributes

  • store_id: Unique store identifier
  • slug: URL slug
  • name: Store name
  • brand: Store brand (e.g., "S-Market", "Prisma")
  • domains: List of domains
  • location: Street address
  • postcode: Postal code
  • postcodeName: City name
  • weeklyOpeningHours: Opening hours for each day
  • categories: SOKCategories object for browsing products

Methods

  • get_filtered_products(slug: str, limit: int = 10) -> list[SOKProduct]: Get products from a specific category

Examples

Finding Stores Near You

api = SOKAPI()

# Get all Prisma stores
prisma_stores = api.get_stores_by_brand("Prisma")
print(f"Found {len(prisma_stores)} Prisma stores")

# Display store information
for store in prisma_stores[:3]:
    print(f"{store.name} - {store.location}, {store.postcode} {store.postcodeName}")

Product Price Comparison

api = SOKAPI()

product = api.get_product_by_id("example-product-id")

if product.pricing:
    pricing = product.pricing
    print(f"Product: {product.name}")
    print(f"Regular Price: {pricing.regularPrice} €")
    print(f"Current Price: {pricing.currentPrice} €")
    if pricing.campaignPrice:
        print(f"Campaign Price: {pricing.campaignPrice} € (valid until {pricing.campaignPriceValidUntil})")
    print(f"Lowest 30-day Price: {pricing.lowest30DayPrice} €")

Browsing Store Categories

api = SOKAPI()
store = api.get_store_by_id("example-store-id")

# Get products from a specific category
dairy_products = store.get_filtered_products("maito-tuotteet", limit=20)
for product in dairy_products:
    print(f"{product.name}: {product.price} €")

or

api = SOKAPI()
store = api.get_store_by_id("example-store-id")

#Get products from a specific category
chewing_gums = store.categories.karkit_ja_suklaat.purukumit.products()

for product in chewing_gums:
    print(f"{product.name}: {product.price} €")

Requirements

  • Python 3.7+
  • requests
  • beautifulsoup4

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Disclaimer

This package is not officially affiliated with S-Group or SOK. Use responsibly and in accordance with S-Group's terms of service.

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

sokpy-0.1.2.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

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

sokpy-0.1.2-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sokpy-0.1.2.tar.gz
  • Upload date:
  • Size: 10.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for sokpy-0.1.2.tar.gz
Algorithm Hash digest
SHA256 a66007930041736afc3cb01ced7eadbdb20c7e6dd21726a3bca4d1e91dcc7334
MD5 49f67556e0dad44b11ed866a295bc7fa
BLAKE2b-256 0c819994b401e11af5572c9c314fed55bd9cbb8f3a1606a6c75f37de66c19d5c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sokpy-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for sokpy-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e9c84cd37f38407e8bdc80f48d2fd124de2853af0ff5099ae87b4854dcec2c54
MD5 3b79f94983bfb2f92466aab567b13583
BLAKE2b-256 5ffa8256b2a2eae07fb5ed4975c370ee3a0c03f1ceda9cc4e1687a8e29927991

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