Skip to main content

A flake8 plugin to detect issues with SQLAlchemy code

Project description

flake8-sqlalchemy

PyPI current version Python Support pre-commit.ci status Code style: black

A flake8 plugin for SQLAlchemy code.

Installation

pip install flake8-sqlalchemy

Configuration

By default, all checks are enabled. You can disable all checks by adding the following to your setup.cfg:

[flake8]
ignore = SQA

or ignore specific checks:

[flake8]
ignore = SQA100

SQA100 - sqlalchemy import alias

Checks that when sqlalchemy is imported with an alias, the alias is either sa or db.

Bad

import sqlalchemy as foo

Good

import sqlalchemy as sa
# or
import sqlalchemy as db

SQA200 - Column keyword argument comment required

When writing a Column definition the comment keyword argument is required. This provides inline documentation for the column, as well as generating the SQL to add the comment to the database.

Bad

class Users(Base):
    __tablename__ = "users"

    id = Column(Integer, primary_key=True)
    name = Column(String)

Good

class Users(Base):
    __tablename__ = "users"

    id = Column(Integer, primary_key=True, comment="User ID from Auth Service")
    name = Column(String, comment="User name: first, middle, last")

Also applies to mapped_column:

class Users(Base):
    __tablename__ = "users"

    id = Column(Integer, primary_key=True, comment="User ID from Auth Service")
    name = mapped_column(String, comment="User name: first, middle, last")

License

This project is licensed under the terms of the MIT license. See the LICENSE file for the full license text.

Author

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

flake8_sqlalchemy-0.2.0.tar.gz (6.4 kB view hashes)

Uploaded Source

Built Distribution

flake8_sqlalchemy-0.2.0-py3-none-any.whl (8.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page