Python SDK for mesahub — access SQLite databases from Python
Project description
MesaHub Python SDK
Python SDK for MesaHub — access SQLite databases from Python with raw SQL or a high-level table API.
Installation
pip install mesahub
Requires Python 3.11+ and httpx.
Quick Start
from mesahub import MesahubClient
client = MesahubClient(
api_key="shs_your_api_key", # from mesahub.app → Settings → API Keys
api_url="https://api.mesahub.app", # or your self-hosted core URL
)
db = client.db("my-app-db") # your database slug from the dashboard
users = db.table("users")
# High-level table API
all_rows = users.find(where={"active": 1}, limit=20)
alice = users.find_one(where={"email": "alice@example.com"})
count = users.count(where={"active": 1})
new_row = users.insert({"name": "Bob", "email": "bob@example.com", "active": 1})
users.update(where={"id": new_row["id"]}, set={"name": "Robert"})
users.delete(where={"id": new_row["id"]})
# Raw SQL
result = db.query("SELECT * FROM users WHERE active = ?", [1])
print(result["rows"]) # [{"id": 1, "name": "Alice", ...}]
db.exec("CREATE TABLE IF NOT EXISTS logs (msg TEXT, created_at TEXT)")
client.close()
Context manager
with MesahubClient(api_key="shs_...", api_url="https://api.mesahub.app") as client:
db = client.db("my-app-db")
rows = db.table("orders").find(where={"status": "pending"})
Connection String
from mesahub import MesahubClient, parse_mesahub_url
info = parse_mesahub_url("mh://shs_abc@mycore.railway.app/mydb")
client = MesahubClient(
api_key=info["api_key"],
api_url=info["api_url"],
route_prefix=info["route_prefix"],
)
db = client.db(info["db_name"])
Format: mh://apikey@host[:port]/dbname
- Remote hosts (e.g.
railway.app) → HTTPS,/v1/routes localhost/ Docker service names /*.internal→ HTTP,/api/routes
WHERE Filters
# Shorthand equality
users.find(where={"active": 1})
# Comparison operators
users.find(where={"age": {"gte": 18}, "score": {"lt": 100}})
# LIKE
users.find(where={"name": {"like": "%alice%"}})
# IN / NOT IN
users.find(where={"role": {"in": ["admin", "editor"]}})
# NULL checks
users.find(where={"deleted_at": {"is_null": True}})
users.find(where={"verified_at": {"is_not_null": True}})
All conditions in a single where dict are combined with AND.
| Operator key | SQL equivalent |
|---|---|
| (plain value) | = ? |
eq |
= ? |
ne |
!= ? |
gt |
> ? |
gte |
>= ? |
lt |
< ? |
lte |
<= ? |
like |
LIKE ? |
not_like |
NOT LIKE ? |
in |
IN (...) |
not_in |
NOT IN (...) |
is_null |
IS NULL |
is_not_null |
IS NOT NULL |
find() Options
users.find(
where={"active": 1},
select=["id", "name", "email"],
order_by=[{"column": "created_at", "direction": "desc"}],
limit=10,
offset=20,
)
insert_many()
db.table("logs").insert_many(
[{"msg": "started"}, {"msg": "done"}],
on_conflict="ignore", # "ignore" | "replace" | None
)
Files
files = db.files
# List
listing = files.list(limit=10, folder_prefix="reports/")
# Upload
record = files.upload(open("report.pdf", "rb").read(), "report.pdf", "application/pdf")
print(record["url"])
# Download
data = files.download(record["id"])
# Delete
files.delete(record["id"])
Error Handling
from mesahub import MesahubError, AuthenticationError, NotFoundError
try:
db.query("SELECT * FROM users")
except AuthenticationError:
print("Invalid API key")
except MesahubError as e:
print(f"[{e.code}] {e.status_code}: {e}")
Self-Hosting
Replace api_url with your own core server URL and optionally set route_prefix="api" for direct Go access (bypassing Caddy):
client = MesahubClient(
api_key="your-admin-token",
api_url="http://localhost:4004",
route_prefix="api",
)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mesahub-1.0.1.tar.gz.
File metadata
- Download URL: mesahub-1.0.1.tar.gz
- Upload date:
- Size: 9.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
282240d5b352bf83153617870515a4ffcc1e125661e38c7b881922c298ec2171
|
|
| MD5 |
0b99bc9941c3883728873aeb524f861a
|
|
| BLAKE2b-256 |
2617a8861b12a4a34541abcba5085b3de4606bf76c3372f50309b7cd61e988e5
|
Provenance
The following attestation bundles were made for mesahub-1.0.1.tar.gz:
Publisher:
publish.yml on mesahub-db/mesahub-pkg-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mesahub-1.0.1.tar.gz -
Subject digest:
282240d5b352bf83153617870515a4ffcc1e125661e38c7b881922c298ec2171 - Sigstore transparency entry: 1496457016
- Sigstore integration time:
-
Permalink:
mesahub-db/mesahub-pkg-python@70f09cfa247113cb67b325ee40505347b69721be -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/mesahub-db
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@70f09cfa247113cb67b325ee40505347b69721be -
Trigger Event:
push
-
Statement type:
File details
Details for the file mesahub-1.0.1-py3-none-any.whl.
File metadata
- Download URL: mesahub-1.0.1-py3-none-any.whl
- Upload date:
- Size: 12.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9d4f92a7f58ee08dd37bc309a371cd1a810dc07a1f0f95a1bbf84abefd169a98
|
|
| MD5 |
70e3a7601fcc7a52d951319e1903d700
|
|
| BLAKE2b-256 |
dc7bbec23e4a203bdf2160e93594a5758399e34346f8d65bdbf50394d39f7598
|
Provenance
The following attestation bundles were made for mesahub-1.0.1-py3-none-any.whl:
Publisher:
publish.yml on mesahub-db/mesahub-pkg-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mesahub-1.0.1-py3-none-any.whl -
Subject digest:
9d4f92a7f58ee08dd37bc309a371cd1a810dc07a1f0f95a1bbf84abefd169a98 - Sigstore transparency entry: 1496457120
- Sigstore integration time:
-
Permalink:
mesahub-db/mesahub-pkg-python@70f09cfa247113cb67b325ee40505347b69721be -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/mesahub-db
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@70f09cfa247113cb67b325ee40505347b69721be -
Trigger Event:
push
-
Statement type: