Skip to main content

A utility package for Caspian projects

Project description

Caspian Utils (casp)

Python is finally reactive.

Caspian Utils is the core utility package behind the Caspian framework ecosystem. It provides the building blocks used by Caspian projects: FastAPI-first plumbing, HTML/template processing, reactive integration patterns, RPC helpers, and common DX utilities.

  • PyPI package name: casp
  • Framework/brand name: Caspian (Caspian Utils is the shared library)

Why Caspian Utils?

Modern web stacks often require a separate Node backend, bundlers, and a growing set of conventions. Caspian projects remove that complexity while keeping the power:

  • Keep the DOM as the source of truth
  • Write async Python for server logic
  • Call server functions directly from the UI via RPC
  • Ship without a bundler or build pipeline

Caspian Utils exists to make those patterns reusable across apps and tooling.


Key Capabilities

FastAPI engine (native async)

Run application logic in async Python and leverage the FastAPI ecosystem (middleware, dependency injection, validation, Starlette sessions, etc.).

Reactive DOM (no build step)

Modify HTML and see changes instantly. No Webpack/Vite required. The DOM is the runtime surface.

File-system routing

Create pages like:

app/users/index.py
app/users/index.html

Caspian projects mount routes automatically based on your folder structure.

Type-safe RPC (no API routes)

Call Python functions directly from the frontend without manually creating REST endpoints.

Prisma ORM integration (optional)

Define your schema once and use an auto-generated, type-safe client in Python (no SQL boilerplate).


Installation

pip install caspian-utils

Python: >=3.11


Quick Start (Conceptual)

A typical Caspian-style app is split into:

  • app/**/index.html for UI
  • app/**/index.py (or actions modules) for backend logic / RPC
  • optional app/**/layout.html for nested layouts

1) Reactive UI in HTML

<!-- app/todos/index.html -->

<!-- 1. Import Python Components -->
<!-- @import { Badge } from ../components/ui -->

<div class="flex gap-2 mb-4">
  <Badge variant="default">Tasks: {todos.length}</Badge>
</div>

<!-- 2. Reactive loop -->
<ul>
  <template pp-for="todo in todos">
    <li key="{todo.id}" class="p-2 border-b">{todo.title}</li>
  </template>
</ul>

<script>
  // 3. State initialized by Python backend automatically
  const [todos, setTodos] = pp.state([[todos]]);
</script>

2) Direct async RPC in Python

# actions.py

from casp.rpc import rpc
from src.lib.prisma.db import prisma

@rpc(require_auth=True)
async def like_post(post_id: str):
    # 1. Direct DB access (async)
    post = await prisma.post.update(
        where={"id": post_id},
        data={"likes": {"increment": 1}},
    )
    # 2. Return data directly to frontend
    return post.likes

3) Call RPC from the frontend

<button onclick="likePost()">Like Post</button>

<script>
  async function likePost() {
    const newCount = await pp.rpc("like_post", { post_id: "123" });
    setLikes(newCount);
  }
</script>

What’s Included

Caspian Utils ships with integrations commonly used in Caspian projects:

  • fastapi, uvicorn
  • jinja2 (templating)
  • beautifulsoup4 (HTML processing)
  • python-dotenv (env loading)
  • slowapi (rate limiting)
  • starsessions (session management)
  • python-multipart (uploads)
  • httpx (HTTP client)
  • tailwind-merge (class merging utility)
  • werkzeug (helpers; used in some tooling)
  • ID utilities: cuid2, nanoid, python-ulid

(Exact dependencies may vary by version; see setup.py in the repository.)


Packaging Notes

If you are publishing to PyPI under caspian-utils, ensure your setup.py matches:

setup(
    name="caspian-utils",
    # ...
)

Repository

Repository


License

MIT


Author

Jefferson Abraham

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

caspian_utils-0.1.3.tar.gz (44.2 kB view details)

Uploaded Source

Built Distribution

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

caspian_utils-0.1.3-py3-none-any.whl (46.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for caspian_utils-0.1.3.tar.gz
Algorithm Hash digest
SHA256 f9d0d8265da9fde7b25e23ec082fe3e8b38df2fc60e6c9d085d9f3f4c52c0966
MD5 7b7e315620f69d4fe2f5be8f48dba5a3
BLAKE2b-256 565674a43fcf0c150786f481112f4324f6886e84ba5304a9bba650f5ecf92924

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for caspian_utils-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 4cbff9d88cc9db030f4de02d32841ac4cb0ab4a6d324f9364ce353573c7735c6
MD5 175ea046a7ac8b3e01cc80029ca48dbf
BLAKE2b-256 5d70f6f31b71ab35ee8b4ddc77e8adb9433a447ec09da549e7794eb9f29a5c8b

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