sphinxcontrib-enumΒΆ

MIT License Ruff PyPI Version Python Versions Development Status Typed Documentation Status Code Coverage Test Status Lint Status OSSF Scorecard

A Sphinx directive for documenting dataclass enums in tabular format. Each member is a row and each dataclass field is a column. Tables can optionally be downloaded as CSV or JSON.

  • Documents enums that mix in a dataclass or whose values are dataclasses (or named tuples).

  • Columns may be any attribute, property or dotted path on the member or its value.

  • Filter and reorder columns and members, rename headers, add captions and cross references.

  • Member docstrings are rendered in a doc column.

  • Optional column legends from field and property docstrings.

  • Customize how cells render with a formatter function.

  • Optional CSV and JSON download buttons (html builders only).

  • Supports enum-properties enums as a special case, and plain enums work too.

For example:

Each dataclass field becomes a column, and field docstrings can describe them in a legend:

@dataclass(frozen=True)
class PlanetData:
    mass: float
    """Mass in kilograms."""

    radius: float
    """Radius in meters."""

    #: Number of known moons.
    moons: int


class Planet(PlanetData, Enum):
    MERCURY = 3.303e23, 2.4397e6, 0
    VENUS = 4.869e24, 6.0518e6, 0
    EARTH = 5.976e24, 6.37814e6, 1
    MARS = 6.421e23, 3.3972e6, 2
.. enum-table:: examples.Planet
   :legend:
   :download: csv, json

name

mass

radius

moons

MERCURY

3.303e+23

2439700.0

0

VENUS

4.869e+24

6051800.0

0

EARTH

5.976e+24

6378140.0

1

MARS

6.421e+23

3397200.0

2

mass

Mass in kilograms.

radius

Radius in meters.

moons

Number of known moons.

Indices and tables