Core myfy patterns and conventions for building applications. Use when working with myfy.core, Application, WebModule, DataModule, FrontendModule, TasksModule, UserModule, CliModule, AuthModule, RateLimitModule, or @route decorators.
You are assisting a developer building an application with the myfy Python framework.
Always import from the public API:
# Core
from myfy.core import Application, provider, SINGLETON, REQUEST, TASK
from myfy.core import BaseSettings, BaseModule
# Web
from myfy.web import WebModule, route, Query, abort, errors
from myfy.web import Authenticated, Anonymous, AuthModule
from myfy.web.ratelimit import RateLimitModule, rate_limit
# Data
from myfy.data import DataModule, AsyncSession
# Tasks
from myfy.tasks import TasksModule, task, TaskContext
# Frontend
from myfy.frontend import FrontendModule, render_template
# User
from myfy.user import UserModule
# CLI Commands
from myfy.commands import CliModule, cli
from myfy.core import Application
from myfy.web import WebModule, route
from myfy.data import DataModule
app = Application(
settings_class=AppSettings, # Optional custom settings
auto_discover=False, # Disable auto-discovery for explicit control
)
# Add modules in dependency order
app.add_module(DataModule())
app.add_module(WebModule())
| Module | Package | Purpose | |--------|---------|---------| | WebModule | myfy-web | HTTP routing, ASGI, FastAPI-like decorators | | DataModule | myfy-data | SQLAlchemy async, migrations, sessions | | FrontendModule | myfy-frontend | Jinja2, Tailwind 4, DaisyUI 5, Vite | | TasksModule | myfy-tasks | Background jobs, SQL-based task queue | | UserModule | myfy-user | Auth, OAuth, user management | | CliModule | myfy-commands | Custom CLI commands | | AuthModule | myfy-web.auth | Type-based authentication, protected routes | | RateLimitModule | myfy-web.ratelimit | Rate limiting per IP or user |
app.py, main.py, or application.py for entry pointBaseSettings from myfy.coreroute decorator from myfy.web@provider(scope=...) decorator from myfy.core@task decorator for background jobsfrom myfy.web import route
from myfy.data import AsyncSession
@route.get("/users/{user_id}")
async def get_user(user_id: int, session: AsyncSession) -> dict:
# session is auto-injected (REQUEST scope)
result = await session.execute(select(User).where(User.id == user_id))
return {"user": result.scalar_one_or_none()}
from myfy.core import provider, SINGLETON
@provider(scope=SINGLETON)
def email_service(settings: AppSettings) -> EmailService:
return EmailService(api_key=settings.email_api_key)
from pydantic import Field
from pydantic_settings import SettingsConfigDict
from myfy.core import BaseSettings
class AppSettings(BaseSettings):
app_name: str = Field(default="my-app")
debug: bool = Field(default=False)
database_url: str = Field(default="sqlite+aiosqlite:///./app.db")
model_config = SettingsConfigDict(
env_prefix="MYFY_",
env_file=".env",
)
from myfy.web import abort, errors
# Quick abort
abort(404, "User not found")
# Typed errors
raise errors.NotFound("User not found")
raise errors.BadRequest("Invalid email", field="email")
Always:
myfy.* not internal modulesSearch for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer