skillfed

sqlalchemy-mate

A library extend sqlalchemy module, makes CRUD easier.

sqlalchemy-mate v2.0.0.3 941.6K downloads/30d#4,678 on PyPI2
Permissive license MIT Active released

What it is and what it does

sqlalchemy_mate is a wrapper library around SQLAlchemy that provides convenience functions for common database operations. It focuses on two main areas: securely loading database credentials from multiple sources (JSON files, environment variables, AWS S3, AWS KMS) without embedding secrets in code, and performing bulk insert/update/upsert operations more efficiently than row-by-row approaches.

The library extends SQLAlchemy's ORM with an ExtendedBase class that adds methods like smart_insert, update_all, and upsert_all directly to your model classes. It also provides an EngineCreator utility that abstracts away connection string construction, supporting PostgreSQL, Redshift, and other databases. The smart_insert strategy attempts bulk operations but falls back to smaller batches when primary key conflicts occur, reducing total commits compared to one-by-one inserts.

Use it for:

  • Load database credentials from JSON files or environment variables without hardcoding secrets in application code.
  • Perform bulk inserts of thousands of records while gracefully handling primary key conflicts without one-by-one retry logic.
  • Automatically update or upsert multiple records by primary key in a single operation using ORM models.
  • Simplify SQLAlchemy connection setup across different database engines (PostgreSQL, Redshift) with a unified API.
  • Integrate AWS KMS decryption into credential loading for cloud-deployed applications.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Simplifies SQLAlchemy code with helper functions for credential management, bulk insert/update/upsert operations, and ORM extensions that reduce boilerplate.

Yes, if you regularly work with SQLAlchemy and need to handle bulk operations or credential management. The library is actively maintained, has no known vulnerabilities, and low install friction. It's most valuable for applications doing frequent bulk inserts with potential conflicts or managing credentials across multiple environments. For simple CRUD operations or single-row inserts, the overhead may not justify the dependency.

Install

sqlalchemy-mate on PyPI

pip

pip install sqlalchemy-mate

uv

uv add sqlalchemy-mate

poetry

poetry add sqlalchemy-mate

Installing sqlalchemy-mate

Before you install

Low install friction with only two runtime dependencies (sqlalchemy and prettytable). Actively maintained with recent commits; last release was 799 days ago but repository shows ongoing activity.

License in practice

MIT license is permissive; you can use this package in commercial and proprietary projects without restriction.

Quickstart

pip install sqlalchemy_mate

from sqlalchemy_mate.api import EngineCreator
ec = EngineCreator.from_env(prefix="DB_DEV")
engine = ec.create_postgresql_psycopg2()

from sqlalchemy_mate.api import ExtendedBase
User.smart_insert(engine, data)

Requires sqlalchemy and prettytable as runtime dependencies; Python 3.8 or later.

Verify before relying

  • Whether smart_insert actually reduces commit count compared to standard bulk operations in practice.
  • Performance characteristics of smart_insert strategy with very large datasets.
  • Compatibility with SQLAlchemy 2.0+ async features and modern connection pooling.

Package facts

License MIT (permissive)
Python support supports the current Python release (>=3.8)
Install friction low — pure-Python wheel
Runtime dependencies 2 — sqlalchemy, prettytable
Maintenance actively maintained — 799 days since the last release
Last repo commit
First released
Downloads 941,565/month — #4,678 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: sqlalchemy_mate-2.0.0.3-py3-none-any.whl

Development Status :: 4 - BetaIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseNatural Language :: EnglishOperating System :: MacOSOperating System :: Microsoft :: WindowsOperating System :: UnixProgramming Language :: PythonProgramming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9

Tags

sqlalchemy bulk insertsqlalchemy credential managementsqlalchemy upsertsqlalchemy orm helpersdatabase connection from jsonsqlalchemy smart insertsqlalchemy update all
orm-helperscredential-managementbulk-operations

More Database packages