Complete Guide to HosteDay Python SDK (hosteday_python)
The official
hosteday_pythonSDK is an async-first, PEP 561 strictly typed (mypy --strict) library for connecting Python backends, desktop/CLI apps, and AI agents to HosteDay viahosteday_config.jsonorHOSTEDAY_*environment variables — with standard CRUD, Auth, Realtime WebSockets (Reverb), Push Notifications, Background Jobs, and an embeddedHostedayWebAppBFF server.
- Official SDK Page: HosteDay Python SDK
- Official PyPI Package: pypi.org/project/hosteday_python
- GitHub Repository: mustafa3max/hosteday-python
- Current Release:
v0.1.0| Requirement:Python >= 3.10| License:MIT
1. Installation & hosteday-setup CLI
A. Recommended Virtual Environment Installation
python3 -m venv .venv
source .venv/bin/activate # Linux / macOS
# <span id="heading-95fffe4035bd1eb79636ad62caba6d02"></span>.venv\Scripts\activate # Windows PowerShell
pip install hosteday_python
Install optional extras when needed:
pip install "hosteday_python[crypto]" # Private-encrypted Realtime channels (PyNaCl)
pip install "hosteday_python[encrypted]" # OS Keyring session storage
pip install "hosteday_python[cli]" # Rich CLI formatting
pip install "hosteday_python[all]" # All optional extras
B. Installing Globally & Solving PEP 668 on Ubuntu/Debian
On Ubuntu 23.04+ and Debian 12+, global pip install raises error: externally-managed-environment (PEP 668):
- For projects: Always use a
.venv. - For the global
hosteday-setupCLI: Install withpipx:
sudo apt install pipx
pipx ensurepath
pipx install hosteday_python
C. Zero-Config Cloud Setup (hosteday-setup)
hosteday-setup connects to the HosteDay Control Plane (https://dash.hosteday.com/api/cli/manifest) and writes your config file with strict 0600 permissions:
# <span id="heading-3cdcd6282c611b97a1f180f2730016e7"></span>Generate hosteday_config.json (default)
hosteday-setup --project my-app --token "<setup_token>" --output hosteday_config.json
# <span id="heading-47c58c932293854781c8bf18cbb27a7d"></span>Or generate a .env file with HOSTEDAY_* variables
hosteday-setup --project my-app --token "<setup_token>" --format env --output .env
Security Note: Never commit
hosteday_config.json,firebase-config.json,.hosteday_session.json, or.envto Git. Always add them to.gitignore.
2. Initialization & Multi-Project Lifecycle (Hosteday & HostedayClient)
Import via either from hosteday import Hosteday or from hosteday_python import Hosteday:
import asyncio
from pathlib import Path
from hosteday import Hosteday, HostedayClient, HostedayConfig, JsonFileHostedayAuthStorage
async def main() -> None:
# 1. Global singleton (auto-discovers sibling firebase-config.json)
await Hosteday.initialize_app(
config_path=Path("hosteday_config.json"),
auth_storage=JsonFileHostedayAuthStorage(Path(".hosteday_session.json")),
)
print("Online:", Hosteday.is_online, "| Host:", Hosteday.client.host)
await Hosteday.dispose()
# 2. Or isolated multi-project client loaded from HOSTEDAY_* env vars
env_cfg = HostedayConfig.from_env()
async with HostedayClient(config=env_cfg) as client:
print("Isolated project:", client.api_base_url)
asyncio.run(main())
Static Pages & Public Storage URLs
HostedayUrlResolver automatically normalizes /api prefixes, locks requests to your project origin, and blocks path traversal:
from hosteday import Hosteday
privacy_url = Hosteday.client.static_pages["privacy"] # https://my-app.hosteday.com/privacy
avatar_url = Hosteday.client.storage_url("avatars/1.png") # https://my-app.hosteday.com/storage/avatars/1.png
3. Standard CRUD Engine & QueryBuilder (index, show, create, update, delete)
All paths omit /api/ automatically, responses are unwrapped cleanly (HostedayResponseReader), and update() auto-falls back from PATCH to PUT on HTTP 404/405:
from hosteday import Hosteday
# <span id="heading-1d44974ceb06c8ee79377869f77ce095"></span>Paginated index with search and Laravel filter encoding
page = await Hosteday.client.index(
"notes",
page=1,
per_page=15,
search="meeting",
filters={"status": ["active", "pinned"]},
with_auth=True,
)
for item in page.items:
print(item["id"], item["data"])
# <span id="heading-d65715cadb8dcbdf36ba3f260ea15a78"></span>Single record (unwrapped directly)
record = await Hosteday.client.show("notes", id=page.items[0]["id"], with_auth=True)
# <span id="heading-9c9f8ffb2287046fb8cef125f32faba8"></span>Create (returns unwrapped record dict directly)
created = await Hosteday.client.create("notes", body={"data": "Hello HosteDay!"})
# <span id="heading-8631b52aa260dda6bda80161c61c76ce"></span>Update (PATCH -> PUT fallback)
updated = await Hosteday.client.update("notes", id=created["id"], body={"data": "Updated note"})
# <span id="heading-f2a6c498fb90ee345d997f888fce3b18"></span>Delete
result = await Hosteday.client.delete("notes", id=updated["id"])
assert result["deleted"] is True
4. Authentication & Pluggable Storage (HostedayAuth)
Supports 10 auth operations, avatar uploads, reactive async streams, and 3 storage backends (MemoryHostedayAuthStorage, JsonFileHostedayAuthStorage with 0600 permissions, and KeyringHostedayAuthStorage):
from pathlib import Path
from hosteday import Hosteday
cred = await Hosteday.auth.sign_in_with_email_and_password(
email="user@example.com",
password="StrongPassword!123",
)
print("Welcome:", cred.user.display_name)
await Hosteday.auth.update_profile(name="Mustafa")
await Hosteday.auth.update_avatar(data=Path("avatar.png").read_bytes(), extension="png")
await Hosteday.auth.send_email_verification()
await Hosteday.auth.reload()
async def watch_user() -> None:
async for user in Hosteday.auth.user_changes():
print("User changed:", user.display_name if user else "Signed out")
await Hosteday.auth.sign_out()
5. Realtime WebSockets (HostedayRealtimeClient)
Supports Pusher v7 / Laravel Reverb with automatic heartbeats, exponential backoff reconnect, and all 4 channel types (PUBLIC, PRIVATE, PRESENCE, and PyNaCl PRIVATE_ENCRYPTED):
from hosteday import Hosteday
# <span id="heading-dab5b913b2b80dc9d494e734eae9bfc4"></span>1. Receive Hybrid Dual-Dispatch notifications on desktop/CLI apps
await Hosteday.realtime.listen_public(
channel="announcements",
event="NotificationReceived",
on_event=lambda e: print("Announcement:", e.payload),
)
# <span id="heading-c59bbdae3ae90df1c99cacfbf356bbe5"></span>2. Private user notification channel (private-user.{id})
await Hosteday.realtime.listen_private(
channel="user.42",
event="NotificationReceived",
on_event=lambda e: print("Private alert:", e.payload),
)
# <span id="heading-a8857e4e2f5bf9322a38c9e563a35219"></span>3. Presence room with member tracking & REST publishing
room = await Hosteday.realtime.subscribe_presence("auction.1")
await Hosteday.realtime.listen_presence_members_list(
channel="auction.1",
on_event=lambda _e: print("Online members:", room.members_count),
)
await Hosteday.realtime.listen_presence(
channel="auction.1",
event="AuctionBidPlaced",
on_event=lambda e: print("New bid:", e.payload),
)
await Hosteday.client.publish_presence_event(
channel="auction.1",
event="AuctionBidPlaced",
payload={"amount": 1500.0, "bidder_name": "Mustafa"},
)
6. Push Notifications, Background Jobs & Connectivity
from hosteday import Hosteday
# <span id="heading-5aa6a2a128478d1d7a1f95805fbde1ca"></span>Push Notifications (FCM + Hybrid Reverb WebSockets)
await Hosteday.notifications.sync_device_token(
token="<fcm_token>",
device_type="web",
device_id="browser-01",
device_name="Chrome Linux",
)
res = await Hosteday.notifications.send_notification(
title="Auction Ending Soon",
body="Only 5 minutes left!",
recipient_user_id="42",
)
# <span id="heading-dab970e99be91f87ed9529a337f3f1e7"></span>Background Jobs
job = await Hosteday.jobs.dispatch(
name="ExportOrdersCsv",
payload={"month": "2026-11"},
delay_seconds=10,
)
status = await Hosteday.jobs.get_status(job.job_id)
# <span id="heading-8d6bef15fa21f3b1ef7d6cd10ad53bc3"></span>Connectivity & Feature Flags
is_online = await Hosteday.connectivity.check_now()
print("Online:", is_online, "| Realtime:", Hosteday.features.is_realtime_enabled)
7. Embedded Web App Server (HostedayWebApp) & Error Handling
HostedayWebApp hides FastAPI and Uvicorn completely, registers built-in /bff/* auth/realtime/notification endpoints, serves SPAs & service workers, and offers one-line web.crud(...):
from pathlib import Path
from hosteday import Hosteday, HostedayException, HostedayWebError
web = Hosteday.create_web_app(
title="HosteDay Notes App",
config_path=Path("hosteday_config.json"),
session_path=Path(".hosteday_web_session.json"),
static_dir=Path("static"),
)
# <span id="heading-bdeb831b9bafbcc4552c928f7fa88925"></span>Register GET/POST/PUT/DELETE /bff/notes in one line:
web.crud("notes", owner_field="user_id")
# <span id="heading-38f015c48aeb0b241237dd9c053fd1ff"></span>Or custom routes (slashless paths auto-normalize to /bff/<path>)
@web.get("summary")
async def get_summary() -> dict[str, int]:
try:
page = await Hosteday.client.index("notes", with_auth=True)
return {"count": len(page.items)}
except HostedayException as exc:
raise HostedayWebError(exc.status_code or 400, exc.display_message) from exc
app = web.asgi_app
if __name__ == "__main__":
web.serve(host="127.0.0.1", port=8000)