Skip to main content

A minimalist Python web framework with minimal external dependencies.

Project description

Asok Framework Logo

GitHub Stars License PyPI Version Python Version Tests Issues Pull Requests


Asok is a cohesive, full-stack Python web framework designed for developer speed, elegant architecture, and security-conscious defaults. Built around a "zero-runtime-dependency" philosophy, it unifies server-side logic and client-side reactivity into a single, high-performance package, offering a streamlined development experience from the first line of code.

๐ŸŒ Official Website & Documentation | ๐Ÿ“– Quick Start Guide | ๐Ÿ’ฌ Join Discord | ๐ŸŽฅ YouTube Tutorials


๐ŸŽฏ Why Asok?

Zero Runtime Dependencies, Maximum Power

Asok requires no external runtime dependencies - just Python 3.10+. No Werkzeug, no Jinja2, no SQLAlchemy. The core framework is built from the Python standard library, making it:

  • โœ… Extremely lightweight (~360KB, ~20K lines of code)
  • โœ… Easy to audit (everything in one codebase, no hidden dependencies)
  • โœ… Forever stable (no dependency hell or supply chain risks)

Modern Developer Experience

# File-based routing like Next.js
src/pages/blog/[slug]/page.py  โ†’  /blog/hello-world

# Client-side Reactivity
<div asok-state="{ count: 0 }">
  <button asok-on:click="count++" asok-text="count"></button>
</div>

# WebSocket Sync
class Counter(Component):
    count = 0

    @exposed
    def increment(self):
        self.count += 1

    def render(self):
        return self.html("counter.html")

# Admin interface in 2 lines
admin = Admin(app)

โœจ Key Features

Core Framework

  • ๐Ÿ’Ž Full Type Hints - Complete PEP 484 support for IDE autocomplete
  • โŒจ๏ธ Powerful CLI - Scaffolding, migrations, dev server, production builds
  • ๐Ÿ›ฃ๏ธ File-based Routing - Next.js-style routing (src/pages/ โ†’ URLs)
  • โ›“๏ธ Dynamic Routes - Parameters via [id], [slug:slug] patterns

Database & ORM

  • ๐Ÿ—„๏ธ Built-in ORM - SQLite (default), PostgreSQL, and MySQL support with relations, migrations, soft deletes
  • ๐Ÿ” Full-Text Search - FTS5/FULLTEXT integration for lightning-fast search
  • ๐Ÿ” Auto Password Hashing - PBKDF2-SHA256 with 600,000 iterations
  • ๐Ÿ“Š Query Builder - Fluent API with eager loading

Templates & Frontend

  • ๐ŸŽจ Template Engine - Jinja-compatible with inheritance and macros
  • โšก Reactive Components - Client-side reactivity (< 3KB, no build step)
  • ๐Ÿ”„ Live Components - Server-driven real-time updates via WebSockets
  • ๐Ÿ’จ HTML Streaming - Chunked responses for instant TTFB
  • ๐ŸŽญ Transitions - Built-in fade/slide/scale animations

High-Performance APIs

  • ๐Ÿ”Œ Native API Engine - Build robust REST APIs with minimal code
  • ๐Ÿ“‘ Auto-OpenAPI - Automatic OpenAPI 3.0 (Swagger) generation for every route
  • ๐Ÿ›ก๏ธ Bearer Token Auth - Built-in secure authentication for stateless clients
  • โšก Optimized JSON - High-speed serialization for high-throughput services
  • ๐Ÿ“‘ Live Documentation - Interactive API explorer (Swagger UI) included

Security

  • ๐Ÿ”’ CSRF Protection - Auto-rotation, HMAC validation, SameSite=Strict
  • ๐Ÿ”’ XSS Prevention - Auto-escaping templates, CSP nonces
  • ๐Ÿ”’ SQL Injection - Parameterized queries, column validation
  • ๐Ÿ”’ Secure Sessions - HttpOnly, Secure flags, HMAC-signed
  • ๐Ÿ”’ Path Traversal - Absolute path validation
  • ๐Ÿ”’ OWASP Top 10 - Built-in protections for common web vulnerabilities

Admin & Developer Tools

  • ๐Ÿ‘จโ€๐Ÿ’ผ Auto Admin - Django-inspired admin in 2 lines of code
  • ๐ŸŒ i18n Ready - Multi-language support with JSON translations
  • ๐Ÿ“ง Email Service - SMTP integration with templates
  • ๐Ÿ“ฆ Production Build - Bytecode compilation, minification, WebP conversion
  • ๐Ÿงช Testing Tools - Built-in test client, fixtures support

๐Ÿ’ญ Philosophy

Asok is designed for developers who want to build modern web applications without managing a complex stack of dependencies. It's a cohesive toolkit where everything works together out of the boxโ€”from database to real-time featuresโ€”while remaining simple enough to understand and audit.

Core Principles:

  • Cohesion over Composition: All components are designed to work together seamlessly
  • Simplicity over Magic: Clear, readable code with minimal abstraction layers
  • Security by Default: Strong security defaults are built in, with additional production hardening available through configuration
  • Developer Joy: Fast feedback loops, intuitive APIs, excellent error messages

Asok doesn't aim to replace existing frameworksโ€”it offers a different approach for teams who value simplicity, security, and rapid development in a unified environment.


๐Ÿ› ๏ธ Installation & Setup

1. Installation

By default, Asok has zero external dependencies and works out of the box with SQLite:

pip install asok

If you wish to use optional database engines or the Redis backend (for caching and sessions), install the corresponding extra(s):

# Optional database engines & capabilities
pip install "asok[postgres]"
pip install "asok[mysql]"
pip install "asok[redis]"
pip install "asok[async]"

# Combined extras (e.g. Postgres + Redis)
pip install "asok[postgres,redis]"

or clone the repo and use the asok/ folder.

2. Create a project

asok create my-project
cd my-project

3. Start the server

asok dev

๐Ÿ—๏ธ Project Structure

โ”œโ”€โ”€ src
โ”‚ย ย  โ”œโ”€โ”€ components                # Reactive components
โ”‚ย ย  โ”œโ”€โ”€ locales                   # JSON translations (en.json, fr.json, ...)
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ en.json                  
โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ fr.json
โ”‚ย ย  โ”œโ”€โ”€ middlewares               # Request interceptors
โ”‚ย ย  โ”œโ”€โ”€ models                    # ORM models (Post.py, User.py)
โ”‚ย ย  โ”œโ”€โ”€ pages                     # YOUR ROUTES (page.py, page.html)
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ page.html
โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ page.py
โ”‚ย ย  โ””โ”€โ”€ partials                  # css, js, images, html, uploads
โ”‚ย ย      โ”œโ”€โ”€ css
โ”‚ย ย      โ”‚ย ย  โ””โ”€โ”€ base.css
โ”‚ย ย      โ”œโ”€โ”€ html
โ”‚ย ย      โ”‚ย ย  โ””โ”€โ”€ base.html
โ”‚ย ย      โ”œโ”€โ”€ images
โ”‚ย ย      โ”‚ย ย  โ””โ”€โ”€ logo.svg
โ”‚ย ย      โ”œโ”€โ”€ js
โ”‚ย ย      โ”‚ย ย  โ””โ”€โ”€ base.js
โ”‚ย ย      โ””โ”€โ”€ uploads
โ””โ”€โ”€ wsgi.py                # Application entry point

๐Ÿ›ฃ๏ธ Routing

Routing is dictated by the structure of the src/pages/ folder. Each folder represents a URL segment, and contains a page.py or page.html file.

  • src/pages/page.html โ†’ /
  • src/pages/about/page.html โ†’ /about
  • src/pages/user/[id]/page.py โ†’ /user/123 (id parameter)
  • src/pages/blog/[slug:slug]/page.py โ†’ /blog/my-post-slug

Dynamic Page Example (src/pages/shop/[cat]/page.py)

from asok import Request 

def render(request: Request):
    category = request.params.get('cat')
    return f"Shop : {category}"

๐ŸŽจ Templates & Inheritance

Templates in src/pages/ can inherit from layouts in src/partials/html/.

Layout (src/partials/html/base.html) :

<!DOCTYPE html>
<html lang="{{ request.lang }}">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="icon" href="{{ static('images/logo.svg') }}" type="image/svg+xml">
    <title>{% block title %}{% endblock %} &mdash; my-project</title>
    <link rel="stylesheet" href="{{ static('css/base.css') }}">
    <script defer src="{{ static('js/base.js') }}"></script>
</head>
<body>
    <main>{% block main %}{% endblock %}</main>
</body>
</html>

Page (src/pages/page.html) :

{% extends "html/base.html" %}
{% block title %}Welcome{% endblock %}

{% block main %}
    <div class="container">
        <img src="{{ static('images/logo.svg') }}" alt="Logo Asok">
        <h1>Welcome to Asok</h1>
        <p>No dependenciesโ€”just Pythonโ€™s standard library</p>
        <p>Edit <code>src/pages/page.html</code> to get started.</p>
    </div>
{% endblock %}

๐Ÿ—„๏ธ AsokDB (The ORM)

Define your models in src/models/.

from asok import Field, Model

class User(Model):
    email = Field.String(unique=True, nullable=False)
    password = Field.Password()
    name = Field.String()
    is_admin = Field.Boolean(default=False)
    created_at = Field.CreatedAt()

๐ŸŒ i18n & Validation

  • Translation: {{ __('welcome') }} (looks in src/locales/).
  • Validation: Validator(data).rule('email', 'required|email').
  • CSRF: {{ request.csrf_input() }} automatic in forms.

๐ŸŽจ Admin Customization

The administration interface is highly customizable:

admin = Admin(app, site_name="My Platform", favicon="images/logo.svg")

Asset Resolution (Smart Resolution)

The admin automatically detects the source of resources:

  • Internal Assets: Files like admin.css or the default logo.svg are served from the package.
  • Project Assets: If you specify a path (e.g. images/logo.svg or uploads/icon.png), the admin will serve them from your resources folder (src/partials/).

๐Ÿš€ Towards Production

Asok supports both WSGI and ASGI. Use Gunicorn for WSGI or Uvicorn for ASGI:

# WSGI (Gunicorn)
gunicorn wsgi:app

# ASGI (Uvicorn) โ€” for async/await support
uvicorn asgi:app

๐Ÿ”’ Production Security Checklist

Asok is built to be secure by default, but production environments require specific configurations to enable all protections.

1. Mandatory Environment Variables

In production (DEBUG=False), Asok enforces strict security checks:

  • SECRET_KEY: Must be at least 32 characters long. Use secrets.token_hex(32) to generate one.
  • APP_URL: Required for Magic Links to prevent Host Header Injection. Example: https://myapp.com.

2. Secure Defaults

  • DEBUG: Default is False. You must explicitly set DEBUG=True in your .env for development.
  • Password Hashing: PBKDF2-SHA256 with 600,000 iterations.
  • Security Headers: HSTS (1 year), CSP (with nonces), X-Frame-Options (DENY), and X-Content-Type-Options (nosniff) are enabled by default.

3. Recommended .env for Production

ASOK_ENV=production
DEBUG=false
SECRET_KEY=your-64-character-ultra-secure-key-here
APP_URL=https://yourdomain.com
DATABASE_URL=sqlite:///data/prod.db

๐Ÿค Contributing

We โค๏ธ contributions! Asok is built to be simple, transparent, and fun to hack on. Whether you're a Python beginner or expert, there's a place for you here.

๐ŸŒŸ Ways to Contribute

๐Ÿš€ Quick Start for Contributors

# 1. Fork and clone the repo
git clone https://github.com/YOUR_USERNAME/asok.git
cd asok

# 2. Create a virtual environment
python -m venv venv
source venv/bin/activate  # or `venv\Scripts\activate` on Windows

# 3. Install dependencies (dev mode)
pip install -e .

# 4. Run the test suite
python -m pytest

# 5. Create a branch for your feature
git checkout -b feature/amazing-feature

# 6. Make your changes and test
python -m pytest -v

# 7. Commit and push
git commit -m "feat: add amazing feature"
git push origin feature/amazing-feature

๐Ÿ“– Read our full Contributing Guide for code style, commit conventions, and more.

๐Ÿ† Contributors

Thanks to all our amazing contributors! ๐ŸŽ‰


๐Ÿ’ฌ Support & Resources

Need help?

Documentation & Resources:

Stay updated:

  • โญ Star the repo to follow development
  • ๐Ÿ‘€ Watch releases for new versions

๐Ÿ—บ๏ธ Roadmap

Asok is actively developed with exciting features planned:

v0.3.0 - Enterprise Ready โœ… Released June 2026

  • Async/ASGI: Full async/await support with ASGI/WSGI dual engine
  • Multi-DB: PostgreSQL & MySQL with connection pooling, vector search
  • Advanced ORM: Polymorphic relations, self-referencing, nested eager loading, N+1 detection
  • WebSocket Rooms: Multi-user collaboration with room broadcasting
  • Redis: Caching, sessions, cache warming, fragment caching
  • Cloud: AWS S3 storage integration
  • Background Jobs: asok worker for async task processing
  • Admin Enhancements: Inline editing, advanced filtering, saved presets, column customization
  • VSCode Extension: Syntax highlighting, IntelliSense, snippets, route navigation
  • Localization: Translation management UI and automatic string extraction
  • Query Optimization: N+1 detection, query analysis, index suggestions, slow query logging

v0.4.0 - GraphQL & Scale (Planned Q4 2026)

  • GraphQL API with auto-generated schemas and subscriptions
  • Advanced WebSocket features (presence, permissions, private messages)
  • Multi-database scaling (read replicas, sharding, load balancing)
  • Plugin ecosystem for third-party extensions
  • Built-in monitoring & observability (Prometheus/Grafana)
  • Advanced SSR & hydration (islands architecture, SSG, ISR)

Note: Timelines are subject to change based on community feedback and development priorities.


๐Ÿญ Production Status

Asok v0.3.0 is actively developed software with growing production adoption. It's suitable for:

โœ… Recommended for:

  • Production web applications and APIs
  • Internal tools and admin dashboards
  • Personal projects and MVPs
  • Rapid prototyping and experimentation
  • Learning full-stack Python development
  • Projects requiring zero runtime dependencies
  • Applications where dependency auditing is critical

โš ๏ธ Current Limitations:

  • Ecosystem: Growing community, limited third-party plugins
  • Maturity: v0.3.x - APIs are stabilizing but may evolve before v1.0

For mission-critical production applications, Asok v0.3.0 provides enterprise features (async, multi-DB, Redis, S3) suitable for production workloads. Evaluate if the current feature set meets your specific requirements.


๐Ÿ“œ 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

asok-0.3.0.tar.gz (413.8 kB view details)

Uploaded Source

Built Distribution

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

asok-0.3.0-py3-none-any.whl (475.0 kB view details)

Uploaded Python 3

File details

Details for the file asok-0.3.0.tar.gz.

File metadata

  • Download URL: asok-0.3.0.tar.gz
  • Upload date:
  • Size: 413.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for asok-0.3.0.tar.gz
Algorithm Hash digest
SHA256 e400313c8cb2b7b8bcef6b543c274bc449779e9b03fe3e2e929a3ca6da8d4a8d
MD5 28937e6f03a8063f3f6cc4132f226cdd
BLAKE2b-256 28b9f97c74fc9c8777498e549a091706d876420b6233ed9dabeb5fd973967819

See more details on using hashes here.

Provenance

The following attestation bundles were made for asok-0.3.0.tar.gz:

Publisher: release.yml on asok-framework/asok

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

File details

Details for the file asok-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: asok-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 475.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for asok-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b0768d25932c44cd892ceab7a23d5278d8cf66fb9f321b2dff0b41af7ff310d3
MD5 e24a26872ac5faa27fefcb6fb99e3bcc
BLAKE2b-256 80bd6c4d934b75706de5456272ca6c917585e4cc64a10b73338ffc3f7038cea7

See more details on using hashes here.

Provenance

The following attestation bundles were made for asok-0.3.0-py3-none-any.whl:

Publisher: release.yml on asok-framework/asok

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