Skip to main content

An async HTTP server for SQLite, FileStorage and WebPage.

Project description

sqless

An async HTTP server for SQLite, FileStorage and WebPage.

Description

sqless is a Python application that provides web service with local database and local file storage.

Installation

pip install sqless

Quick Start

Running the server

sqless --host 127.0.0.1 --port 12239 --secret your-secret-key

This will create www directory in the current directory, which is used for WebPage. You can access the www/index.html at http://127.0.0.1:12239/index.html

It will also creates db and fs directories in the current directory, when saving data by database API and file storage API.

Using the database API

import requests

# Set up the base URL and authentication
BASE_URL = "http://127.0.0.1:12239"
SECRET = "your-secret-key"
DB_TABLE = "users"

# Insert or update data
r = requests.post(
    f"{BASE_URL}/db/{DB_TABLE}",
    headers={"Authorization": f"Bearer {SECRET}"},
    json={"key": "U001", "name": "Tom", "age": 14}
)

# Query data
r = requests.get(
    f"{BASE_URL}/db/{DB_TABLE}/key = U001",
    headers={"Authorization": f"Bearer {SECRET}"}
)

# Fuzzy query
r = requests.get(
    f"{BASE_URL}/db/{DB_TABLE}/name like %om%?limit=10&page=1",
    headers={"Authorization": f"Bearer {SECRET}"}
)

# Value query
r = requests.get(
    f"{BASE_URL}/db/{DB_TABLE}/age > 10?limit=10&page=1",
    headers={"Authorization": f"Bearer {SECRET}"}
)

# Delete data
r = requests.delete(
    f"{BASE_URL}/db/{DB_TABLE}/key = U001",
    headers={"Authorization": f"Bearer {SECRET}"}
)
  • {BASE_URL}/db/users will read/write records in users table in db/default.sqlite.

  • {BASE_URL}/db/mall-users will read/write records in users table in db/mall.sqlite.

  • {BASE_URL}/db/east-mall-users will read/write records in users table in db/east/mall.sqlite.

Using the FileStorage API

import requests

# Upload a file to ./fs/example.txt
with open("example.txt", "rb") as f:
    r = requests.post(
        f"{BASE_URL}/fs/example.txt",
        headers={"Authorization": f"Bearer {SECRET}"},
        files={"file": f}
    )

# Check if a file exists
r = requests.get(
    f"{BASE_URL}/fs/example.txt?check=1",
    headers={"Authorization": f"Bearer {SECRET}"}
)

# Download a file
r = requests.get(
    f"{BASE_URL}/fs/example.txt",
    headers={"Authorization": f"Bearer {SECRET}"},
    stream=True
)
with open("downloaded_example.txt", "wb") as f:
    for chunk in r.iter_content(chunk_size=8192):
        f.write(chunk)

Using the Proxy API

import requests
import base64

payload = {
    "method": "POST",
    "url": "https://httpbin.org/post",
    "headers": {
        "User-Agent": "SQLESS-Client/1.0",
        "Authorization": "Bearer mytoken"
    },
    "type": "form",
    "data": {"foo": "bar"},
    "files": [
        {
            "field": "file1",
            "filename": "example.txt",
            "content_type": "text/plain",
            "base64": base64.b64encode(open("example.txt", "rb").read()).decode()
        }
    ]
}

r = requests.post(
    f"{BASE_URL}/xmlhttpRequest",
    headers={"Authorization": f"Bearer {SECRET}"},
    json=payload
)
print(r.json())

License

This project is licensed under the MIT License - see the LICENSE file 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

sqless-0.1.3.tar.gz (14.9 kB view details)

Uploaded Source

Built Distribution

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

sqless-0.1.3-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

Details for the file sqless-0.1.3.tar.gz.

File metadata

  • Download URL: sqless-0.1.3.tar.gz
  • Upload date:
  • Size: 14.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for sqless-0.1.3.tar.gz
Algorithm Hash digest
SHA256 ff706a6f0a37c1afb0ba6e627981678a572b6f4b66e641223eac2e00f0cd2268
MD5 9b0dcb7cdbaef52ff2a6d3101f57fcda
BLAKE2b-256 e2eef72bba7e197b54dff41d64ae0670ca69b8860cb83d23a65513ef27655ea3

See more details on using hashes here.

File details

Details for the file sqless-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: sqless-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 14.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for sqless-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 3ef14e31c90b31bb1deeb856b2f822366890ddbbacd874e19819b698822b21ae
MD5 b37f90b47a1cd3227f14a336afb09ba1
BLAKE2b-256 a89f9eb07ef43732eb4a7cd37aae5523d6a5364a8f6351e6ceb11b992b5f8e17

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