data-module_skill

This skill integrates async SQLAlchemy data access with request-scoped sessions and pool management to simplify robust database operations.
  • Python

83

GitHub Stars

1

Bundled Files

2 months ago

Catalog Refreshed

4 months ago

First Indexed

Readme & install

Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.

Installation

Preview and clipboard use veilstrat where the catalogue uses aiagentskills.

npx veilstrat add skill psincraian/myfy --skill data-module

  • SKILL.md5.1 KB

Overview

This skill provides an async DataModule for SQLAlchemy-enabled database access with connection pooling and request-scoped AsyncSession injection. It simplifies using AsyncSession in web routes, background jobs, and providers while offering sensible defaults and environment-driven configuration. The module supports auto-creating tables in development, explicit session factories for background work, and guidance for Alembic migrations.

How this skill works

On startup the DataModule configures an async SQLAlchemy engine and a session factory using environment variables prefixed with MYFY_DATA_. HTTP request handlers and providers receive a REQUEST-scoped AsyncSession automatically, ensuring one session per request. For background or singleton services you obtain sessions from the SessionFactory using an async context manager to ensure proper lifecycle and connection pooling.

When to use it

  • Building async web routes that need database access with automatic session injection
  • Running background tasks or workers that need manual session lifecycle control
  • Managing connection pooling and tuning pool parameters for production databases
  • Performing schema changes via Alembic while keeping runtime code separate
  • Quick development setups where auto-creating tables may speed iterations

Best practices

  • Use async DB drivers (asyncpg for PostgreSQL, aiosqlite for SQLite, aiomysql for MySQL)
  • Keep sessions request-scoped; do not share sessions across requests or threads
  • Use Alembic migrations for production; only enable auto_create_tables in development
  • Tune pool_size, max_overflow, and pool_timeout to match expected concurrency
  • Enable pool_pre_ping to catch stale connections before use
  • Wrap multi-step DB changes in transactions and commit once when ready

Example use cases

  • Route handler: inject AsyncSession into HTTP endpoints to run queries and commits
  • Background worker: use SessionFactory.session_context() for manual session lifecycle in long-running jobs
  • Provider/repository: create a REQUEST-scoped repository that receives an AsyncSession
  • Local development: enable auto_create_tables with metadata to bootstrap schemas rapidly
  • Migrations: configure Alembic target_metadata from your declarative Base and run autogenerate

FAQ

Inject SessionFactory and use async with factory.session_context() to obtain a session; this ensures proper closing and pooling.

Can I auto-create tables in production?

No. auto_create_tables raises an error when MYFY_DATA_ENVIRONMENT is production; use Alembic migrations instead.

Built by
VeilStrat
AI signals for GTM teams
© 2026 VeilStrat. All rights reserved.All systems operational