Skip to main content

Sokoweb package

Project description

SokoWeb – DHT-Based Commerce Network

A distributed commerce network using Kademlia DHT for peer-to-peer product/service listings, search, and discovery.

Quick Start

pip install sokoweb==0.1.21
sokoweb-up
or sokoweb-up -d (detached mode)

You'll be prompted for:

  • NODE_PORT (default: 8000)
  • NODE_TCP_PORT (default: 8500)
  • ADVERTISE_IP (default: localhost)

Note: Use public IP/domain to join network. Localhost works for exploration but won't connect. Tunneling services like Ngrok typically won't work as network requires UDP and TCP access.

Requirements

  • Python 3.9+
  • Docker 27.3.1+
  • docker compose 2.29.7+

API Examples

Register User

curl -X POST http://localhost:8000/register \
  -H "Content-Type: application/json" \
  -d '{
    "username": "alice",
    "password": "alice123",
    "email": "alice@example.com",
    "full_name": "Alice Wonderland",
    "phone_number": "+254712345678",
    "scopes": ["products:write", "products:read", "credits:manage"]
  }'

Get Access Token

curl -X POST http://localhost:8000/token \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "username=alice&password=alice123&scope=products:write products:read credits:manage"

Available scopes:

  • products:write - Create/modify products
  • products:read - View products
  • credits:manage - Purchase/manage credits
  • categories:write - Suggest categories
  • categories:read - View categories

Post Product

curl -X POST http://localhost:8000/products \
  -H "Authorization: Bearer <your_token>" \
  -H "Content-Type: application/json" \
  -d '{
    "core": {
      "name": "Smartphone",
      "category": "Electronics",
      "price": 500.00,
      "description": "New smartphone",
      "seller_phone": "+254712345678",
      "shop_name": "Tech Store",
      "seller_location": [-1.2921, 36.8219]
    },
    "extended": {
      "storage_duration_days": 1,
      "tags": ["samsung S21","5G"],
      "metadata": { "color": "black" }
    }
  }'

Upload Product Image

curl -X POST http://localhost:8000/products/{product_id}/image \
  -H "Authorization: Bearer <your_token>" \
  -F "image=@/path/to/image.jpg"

Retrieve Products

By ID

curl http://localhost:8000/products/{product_id} \
  -H "Authorization: Bearer <your_token>"

Search by category/shop

curl "http://localhost:8000/products?category=Electronics&shop_name=Tech%20Store" \
  -H "Authorization: Bearer <your_token>"

Search by location (within radius)

curl "http://localhost:8000/products?latitude=-1.2921&longitude=36.8219&radius_km=10" \
  -H "Authorization: Bearer <your_token>"

Combined search

curl "http://localhost:8000/products?category=Electronics&latitude=-1.2921&longitude=36.8219&radius_km=5" \
  -H "Authorization: Bearer <your_token>"

Retrieve Product Images

1. Retrieve Single Image

Use this to get the first (or only) associated image of a product:

curl "http://localhost:8000/products/{product_id}/image" \
  -H "Authorization: Bearer <your_token>"
  • Returns the raw bytes of the image (e.g., "image/png" if PNG)
  • You can save/open it directly as an image file if you use a tool like curl with "-o" or Postman's "Save Response"

2. Retrieve All Images (Multi-Image ZIP)

Use this to get all images for a product in a single ZIP file:

curl "http://localhost:8000/products/{product_id}/images" \
  -H "Authorization: Bearer <your_token>" \
  --output images_{product_id}.zip
  • Responds with a ZIP file (the beginning bytes are "PK", indicating a .zip)
  • If you simply view the response as text, you'll see nonsense characters (binary contents). Instead, save it to disk (e.g., --output in curl) and then open with any ZIP program. You'll find all images included in that archive

Credits Management

Check Balance

curl http://localhost:8000/credits/balance \
  -H "Authorization: Bearer <your_token>"

Purchase Credits

curl -X POST http://localhost:8000/credits/purchase \
  -H "Authorization: Bearer <your_token>" \
  -H "Content-Type: application/json" \
  -d '{
    "amount": 100,
    "phone_number": "+254712345678"
  }'

Category Operations

# Suggest a new category (only works in production)
curl -X POST http://<your-public-ip>:8000/categories/suggest \
  -H "Authorization: Bearer <your_token>" \
  -H "Content-Type: application/json" \
  -d '{
    "category_name": "Smart Home"
  }'

# Retrieve all categories
curl http://localhost:8000/categories \
  -H "Authorization: Bearer <your_token>"

Note: Substitute localhost with your Public IP in production. The same applies for port, if it's different in your case.

Network Management

  • View your containers: docker ps
  • Shut down the network: sokoweb-down

Contributing

This project is open source and contributions are welcome.

License

MIT License

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

sokoweb-0.1.29.tar.gz (52.9 kB view details)

Uploaded Source

Built Distribution

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

sokoweb-0.1.29-py3-none-any.whl (60.8 kB view details)

Uploaded Python 3

File details

Details for the file sokoweb-0.1.29.tar.gz.

File metadata

  • Download URL: sokoweb-0.1.29.tar.gz
  • Upload date:
  • Size: 52.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.12

File hashes

Hashes for sokoweb-0.1.29.tar.gz
Algorithm Hash digest
SHA256 49dedb21c7832e00bb341e9393a1c6bc50a78e019e14382cd8d974ddc5a23908
MD5 dbaca9ff7e268e75f27ff9bb6e4713be
BLAKE2b-256 a0d79d2df00ba3f50842fcbba3dec7bcd4ade5691085caac61707e461f055941

See more details on using hashes here.

File details

Details for the file sokoweb-0.1.29-py3-none-any.whl.

File metadata

  • Download URL: sokoweb-0.1.29-py3-none-any.whl
  • Upload date:
  • Size: 60.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.12

File hashes

Hashes for sokoweb-0.1.29-py3-none-any.whl
Algorithm Hash digest
SHA256 26c752c67a6d3b789e5e44a59ec07c3af43a8c7b429dd026c955fc09b0d8b2e2
MD5 b8d1bfae721e2c2078dbe5c9a4bff4ba
BLAKE2b-256 8ddc60a314789e189969d27555fad24d8dd8c2c40e03dbd34df20f42d2e1a56a

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