Skip to main content

Ushka is a minimal, experimental Python micro-framework for hobbyists and solo developers. Its goal is to enable rapid API development with **zero boilerplate** by using file-based routing.

Project description

Ushka

Ushka is a minimal, experimental Python ASGI web framework based on file-based routing.

⚠️ Alpha Stage: Not Production Ready

This is an early alpha release. The project is in active, unstable development. The API may change at any time.

Core Concept: File-Based Routing

The filesystem is the API. Ushka scans a routes/ directory and maps the file and directory structure directly to URL paths.

  • A file like routes/hello.py becomes the endpoint /hello.
  • A file named routes/index.py becomes the root endpoint /.
  • Nested directories become nested paths. routes/api/v1/status.py becomes /api/v1/status.
  • Dynamic paths are created using square brackets in the filename. routes/users/[id].py becomes the endpoint /users/[id].
  • The HTTP method is determined by the function name inside the file (e.g., get(), post()).

Example

This example uses autodiscovery to create a simple API.

Project Structure

examples/
├── app.py
└── routes/
    ├── hello.py
    ├── index.py
    └── hello/
        └── [name].py

1. The Route Handlers (examples/routes/)

These files contain the functions that will handle requests.

examples/routes/index.py (handles GET /)

def get():
    return "Welcome to the autodiscovered example!"

examples/routes/hello.py (handles GET /hello)

def get():
    return "Hello, World!"

examples/routes/hello/[name].py (handles GET /hello/[name])

def get(name: str):
    return f"Hello, {name}!"

2. The Main Application (examples/app.py)

This file creates the Ushka application and tells it to automatically discover the routes.

from ushka import Ushka
from pathlib import Path

app = Ushka()

# Autodiscover routes from the 'routes' directory
routes_path = Path(__file__).parent.joinpath("routes")
app.router.autodiscover(base_path=routes_path)

if __name__ == "__main__":
    print("Starting Ushka server on http://127.0.0.1:8000")
    app.run("127.0.0.1", 8000)

How to Run the Example

  1. Navigate to the project root.
  2. Run the application:
    python examples/app.py
    
  3. Test the routes in your browser or with curl:
    • curl http://127.0.0.1:8000/
    • curl http://127.0.0.1:8000/hello
    • curl http://127.0.0.1:8000/hello/Developer

Manual Routing

For more complex scenarios, you can add routes manually. This is useful if you prefer not to use file-based routing.

from ushka import Ushka

app = Ushka()

def my_handler():
    return "This was added manually."

app.router.add_route("GET", "/manual", my_handler)

Roadmap

  1. Stabilize and Enhance the Router: Improve the routing system and its features.
  2. Request/Response Objects: Implement robust Request and Response objects.
  3. Middleware: Add support for middleware.
  4. CLI: Create a simple CLI for project scaffolding.
  5. Dependency Injection: Explore a simple DI system.

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

ushka-0.0.2.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

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

ushka-0.0.2-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file ushka-0.0.2.tar.gz.

File metadata

  • Download URL: ushka-0.0.2.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ushka-0.0.2.tar.gz
Algorithm Hash digest
SHA256 4fb60a4d4c4e5ef3d8e4abd6ca5674d705ee13c828844918b10f55fb521d67f6
MD5 35be46833736ac8b169942ddbae45314
BLAKE2b-256 8d91af38f80bc80480f8fe14f000c4f70918dbefc3bdef88e2eb5579e43daf0a

See more details on using hashes here.

Provenance

The following attestation bundles were made for ushka-0.0.2.tar.gz:

Publisher: python-publish.yml on kleber-code/ushka

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ushka-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: ushka-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ushka-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5e608518498d8f95a7a75c01de627d161f5a6491fb5efc70254566ae93f34d60
MD5 dfc849f5081ea2cf684a8da08bbaa53e
BLAKE2b-256 2eddc638b9c4ce8000da20df476cca8f1b8ed3e668909e7d6e4a612cfe49af37

See more details on using hashes here.

Provenance

The following attestation bundles were made for ushka-0.0.2-py3-none-any.whl:

Publisher: python-publish.yml on kleber-code/ushka

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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