Skip to main content
author:

Lele Gaifax

contact:

lele@metapensiero.it

license:

GNU General Public License version 3 or later

This is a very simple extension to Sphinx that injects the ability to recognize and pretty print SQLAlchemy statements into its automodule and autoclass directives.

To use it, first of all you must register the extension within the Sphinx environment, adding the full name of the package to the extensions list in the file conf.py, for example:

# Add any Sphinx extension module names here, as strings.
extensions = ['metapensiero.sphinx.autodoc_sa']

Without further settings it uses the default SQLAlchemy stringification strategy, but you can explicitly choose the right dialect by setting autodoc_sa_dialect to a string containing its fully qualified name, for example:

autodoc_sa_dialect = 'sqlalchemy.dialects.postgresql.dialect'

Otherwise, you can set it using the -D option of the sphinx-build command, e.g. adding -D autodoc_sa_dialect=my.own.dialect to the SPHINXOPTS of the Makefile created by sphinx-quickstart.

At this point, any documented SQLAlchemy core statement or ORM query, appearing either at the module level or as a class attribute, will be compiled into SQL, beautified using sqlparse.format() and added to the documentation wrapped within a code-block:: sql directive.

If you chose a specific SQLAlchemy dialect, by any chance you may want to select the right Pygments lexer to adjust the highlighting rules, instead of the default sql:

autodoc_sa_pygments_lang = 'postgresql'

If you are using PostgreSQL, you may prefer using the pglast SQL prettifier over the default one based on sqlparse:

autodoc_sa_prettifier = 'pglast'

Metadata

Release files for metapensiero.sphinx.autodoc-sa 2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for metapensiero.sphinx.autodoc-sa 2.2
File Size Uploaded
metapensiero_sphinx_autodoc_sa-2.2.tar.gz 11.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for metapensiero.sphinx.autodoc-sa 2.2
File Interpreter ABI Platform
metapensiero_sphinx_autodoc_sa-2.2-py3-none-any.whl Python 3 none any Details

Total release size: 17.0 kB

Release files / metapensiero_sphinx_autodoc_sa-2.2.tar.gz

Download URL metapensiero_sphinx_autodoc_sa-2.2.tar.gz
Size 11.7 kB
Tags Source
SHA-256 checksum
How to use checksums
5caa1df612973ef8527c4cdf23600e3cf39c110c078ba9ef9667b474a083f276
BLAKE2b-256 checksum
How to use checksums
63cfe58fe0fdde0e698031b0fc37de093f323a1a5255337eeeb4fae23e910ff3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.10

Release files / metapensiero_sphinx_autodoc_sa-2.2-py3-none-any.whl

Download URL metapensiero_sphinx_autodoc_sa-2.2-py3-none-any.whl
Size 5.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b845fdad56cb953fbc1f9183047a1d5c83044611274630ff1ac9a7ba840cef36
BLAKE2b-256 checksum
How to use checksums
18843ceb4f6eb64f3e4580d0f8301461d4ab0997b0e36bb60c8ba19d680c3036
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.10

Release history Release notifications | RSS feed

This release

2.2 This release

2 release files

2.1

1 release file

2.0

1 release file

1.7

1 release file

1.6

1 release file

1.5

1 release file

1.4

1 release file

1.3

1 release file

1.2

1 release file

1.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page