Skip to main content

Pancake - Decorator-driven Python web framework with IoC, MyBatis ORM, and AI workflow

Project description

Pancake Framework

A decorator-driven Python framework with Spring-inspired IoC, MyBatis Plus ORM, AI workflow, and a plugin system.

Python License PyPI

English | 中文文档

Features

  • Dough IoC Container — Spring-style Bean management with full lifecycle: on_initon_starton_stopon_destroy
  • Decorator-Driven@singleton, @prototype, @lazy, @inject, @config, @depends_on
  • Async First — All lifecycle methods support async def; DoughFactory handles sync/async transparently
  • Zero Import — The pancake-embed plugin injects all decorators and classes into builtins
  • Base ClassesConfiguration (bean factory), Service, Struct (dataclass + Dough), Function
  • MyBatis Plus ORM@Mapper, @Select/@Insert/@Update/@Delete, chain queries qw(), dynamic SQL, pagination
  • aiohttp Web Server@controller, @get/@post, parameter binding, middleware, exception handling, CORS
  • Jinja2 Templates@template decorator for automatic HTML rendering
  • Spring Security-Style — Authentication/authorization, JWT, CSRF, rate limiting, security headers
  • AI Module — Unified LLM client (OpenAI/DeepSeek/Gemini/Ollama), short/long-term memory, RAG
  • Redis Cache@cached decorator, CacheGuard (anti-penetration/avalanche/breakdown)
  • Message Queue@event_node/@on_event event-driven, SimpleBroker/RedisBroker
  • Remote CallsHttpRemote/GrpcRemote HTTP and gRPC clients
  • LangGraph Workflow@langgraph_node/@langgraph_edge state graph orchestration
  • GUI/CUI — Flet desktop GUI and Click CLI framework integration
  • Plugin System — XML declarative management, auto pip install, pancake plugin CLI

Quick Start

Install

pip install pancake_framework

Create Project

pancake create myapp
cd myapp

Run

python main.py
# or
pancake run

Project Structure

myapp/
├── main.py                  # Entry point
├── pancake.xml              # Plugin and global config
├── pyproject.toml           # Project metadata
└── src/
    ├── resource/
    │   ├── yaml/            # YAML config
    │   │   └── service.yaml
    │   └── json/            # JSON config
    └── templates/           # HTML templates

Core Concepts

Dough IoC System

The core of Pancake is the Dough system — a Spring-style IoC container. All Beans extend the Dough base class and are managed by DoughFactory.

Bean Lifecycle

__init__()  →  on_init()  →  on_start()  →  [running]  →  on_stop()  →  on_destroy()
   construct    @PostConstruct    ready                        stop         @PreDestroy

Scopes

Scope Decorator Description
Singleton @singleton One instance per factory (default)
Prototype @prototype New instance every resolve
Lazy @lazy Created on first access

Base Classes

Base Purpose
Service Service class, method collection
Configuration Config class, non-private method return values auto-register as Beans
Struct Data structure, inherits dataclass, for DTOs/forms
Function Function wrapper, provides call() method

Zero Import

With the pancake-embed plugin enabled, all decorators and classes are auto-injected into builtins:

# No imports needed
@singleton
@depends_on("DatabaseService")
class UserService(Service):
    async def on_init(self):
        self.db = DoughFactory.get().resolve("DatabaseService")

    async def find_user(self, user_id: int):
        return await self.db.query(user_id)

Decorators

Decorator Target Description
@dough Class Mark class as Bean
@singleton Class Singleton scope
@prototype Class Prototype scope
@lazy Class Lazy initialization
@service Class Convert to Service subclass
@configuration Class Convert to Configuration subclass
@struct Class Mark as data structure (dataclass)
@function Function Convert to Function subclass
@inject Class/Function Auto-inject dependencies by type
@inject_name Class/Function Auto-inject dependencies by name
@config Class Inject Struct fields from settings
@depends_on("A", "B") Class Declare Bean dependencies
@import_class(Cls) Class Auto-register external classes
@maker Method Mark method return value as Bean
@no_maker Method Exclude method from auto-registration

Plugin System

Pancake uses a plugin architecture. All extensions are provided as plugins, declared in pancake.xml <dependencies>.

Plugins

Plugin Package Description
embed pancake-embed Zero import, inject into builtins
mybatis pancake-mybatis MyBatis Plus ORM
web pancake-web aiohttp Web server
web-template pancake-web-template Jinja2 template rendering
web-security pancake-web-security Spring Security-style security
ai pancake-ai AI model integration
redis pancake-redis Redis cache
langgraph pancake-langgraph LangGraph workflow
remote pancake-remote HTTP/gRPC remote calls
cui pancake-cui Click CLI framework
gui pancake-gui Flet desktop GUI

Plugin Management

pancake plugin list              # List configured plugins
pancake plugin add <name>        # Add plugin to pancake.xml
pancake plugin remove <name>     # Remove plugin
pancake plugin clear             # Clear all plugins

pancake.xml

<?xml version="1.0" encoding="UTF-8"?>
<pancake>
    <config>
        <service.title>myapp</service.title>
        <service.port>8080</service.port>
    </config>
    <dependencies>
        <dependency>
            <groupId>io.pancake</groupId>
            <artifactId>embed</artifactId>
        </dependency>
        <dependency>
            <groupId>io.pancake</groupId>
            <artifactId>mybatis</artifactId>
        </dependency>
        <dependency>
            <groupId>io.pancake</groupId>
            <artifactId>web</artifactId>
        </dependency>
    </dependencies>
</pancake>

Documentation

Module Description
Framework Tutorial (English) Complete tutorial covering core concepts and all plugins
框架教程 (中文) 完整教程,涵盖核心概念和所有插件

Optional Dependencies

pip install pancake_framework[ai]          # AI module (openai)
pip install pancake_framework[redis]       # Redis cache
pip install pancake_framework[sqlite]      # SQLite database
pip install pancake_framework[postgres]    # PostgreSQL database
pip install pancake_framework[mysql]       # MySQL database
pip install pancake_framework[langgraph]   # LangGraph workflow
pip install pancake_framework[grpc]        # gRPC remote calls
pip install pancake_framework[gui]         # Flet GUI
pip install pancake_framework[all]         # All optional deps

Architecture

pancake/                    # Framework core
├── __init__.py             # Entry: init() → run()
├── run.py                  # Pipeline: load_xml → load_config → load_ovenware → load_dish → build
├── dough.py                # Dough base, Scope enum, DoughMeta metaclass
├── registry.py             # Global registry: flour/water/egg/sugar
├── decorators/             # Decorators: scope/bean/inject/config/convert
├── settings.py             # Centralized config management
├── base/                   # Base classes: Configuration, Service, Struct, Function
├── factory/                # DoughFactory + PackageManager
├── builder/                # Build pipeline: load_dlc(plugins) + load_src(user code) + build
├── cli/                    # CLI: init/create/run/check/build/plugin/config/audit
├── ovenware/               # Plugin base InitAction + Broker messaging
├── resource/               # Config loaders: YAML/JSON/XML + logging + hot reload
└── tool/                   # Utilities: ProgressBar

CLI Commands

pancake version              # Show version
pancake init                 # Initialize project in current directory
pancake create <name>        # Create new project
pancake run                  # Run project
pancake check                # Check project structure and environment
pancake build                # Build project as wheel
pancake config show          # Show current config
pancake audit                # Audit code quality
pancake update               # Update framework
pancake install              # Install missing dependencies

Startup Flow

main.py → pancake.run()
  ├── init()                    # Environment check, structure check, load dotenv/logging
  └── run.py → run()
      ├── load_xml()            # Load pancake.xml → plugin list + global config
      ├── load_config()         # Load YAML/JSON → settings
      ├── load_ovenware()       # Load plugins (sorted by init_order)
      ├── load_dish()           # Load user code from src/
      ├── build()               # Create Beans → topological sort → on_init → on_start
      └── run_loop_methods()    # Run loop_method (e.g., Web server)

Tests

pip install pytest pytest-asyncio
python -m pytest tests/ -v

License

MIT

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

pancake_framework-0.2.8.tar.gz (47.6 kB view details)

Uploaded Source

Built Distribution

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

pancake_framework-0.2.8-py3-none-any.whl (63.0 kB view details)

Uploaded Python 3

File details

Details for the file pancake_framework-0.2.8.tar.gz.

File metadata

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

File hashes

Hashes for pancake_framework-0.2.8.tar.gz
Algorithm Hash digest
SHA256 66e3fd1b7a3190850776fdac6d5376228a055b85977c772cec2ab63596bd4747
MD5 c7fb93dec5169e79dedec4a8c417f333
BLAKE2b-256 764347bcfeba8b5ff10ef4cbf0238b444f9b669851efed9e123348839a46f9bd

See more details on using hashes here.

Provenance

The following attestation bundles were made for pancake_framework-0.2.8.tar.gz:

Publisher: publish.yml on PancakeFramework/PancakeFramework

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

File details

Details for the file pancake_framework-0.2.8-py3-none-any.whl.

File metadata

File hashes

Hashes for pancake_framework-0.2.8-py3-none-any.whl
Algorithm Hash digest
SHA256 55d51081c281ba77e36817aa61ce2c07e88e314b216a5313f01c4709a65310dc
MD5 ffb7498edfc9288bf7703eee8716847a
BLAKE2b-256 edef359f51dc84a5ca35d7b6c6dda8995893ebee0ea45332f0a467ce9282f2aa

See more details on using hashes here.

Provenance

The following attestation bundles were made for pancake_framework-0.2.8-py3-none-any.whl:

Publisher: publish.yml on PancakeFramework/PancakeFramework

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