Skip to main content

sphinx-eu-ai-label

A Sphinx extension for adding the European Commission's icons for labelling AI-generated content to your documentation.

See it in action at https://doismellburning.github.io/sphinx-eu-ai-label/.

The icons

The Commission publishes three icons:

Kind Use it when The icon says
basic AI was involved in creating the content, or you want to write your own label text "AI"
generated The content was fully generated by AI, with no human-created elements or editorial control apart from prompting "AI GENERATED"
modified Existing human-made content was partially modified with AI "AI MODIFIED"

Each icon comes in four colour variants: black, white, black-50 and white-50 (the last two are 50% transparent). The white variants are for dark backgrounds.

Because the icons carry their own wording, labels show the icon on its own unless you add text.

Installation

Install it from PyPI:

pip install sphinx-eu-ai-label

It needs Python 3.10 or later and Sphinx 8 or later.

Then add it to your conf.py:

extensions = [
    # ...
    "sphinx_eu_ai_label",
]

Usage

Directive

Use the directive to put a block-level label at the top of a page or section. With no argument it uses the basic icon.

.. ai-label:: generated

For the basic icon, the text goes before the icon, so this reads "Summary generated with [AI]". For the other icons, the text goes after the icon.

.. ai-label:: basic
   :text: Summary generated with
   :variant: white
   :align: right

The text can contain inline markup, such as a link to a page about how you use AI:

.. ai-label:: basic
   :text: Summary generated with `help <ai-policy.html>`_ from

MyST Markdown:

```{ai-label} modified
:text: Illustrations modified with AI
```
Option Values Default
(argument) basic, generated, modified basic
:text: Text to show next to the icon. It can contain inline markup, such as a link to your AI policy. Pass an empty value to show the icon on its own, even if eu_ai_label_texts sets text eu_ai_label_texts, or none
:variant: auto, black, white, black-50, white-50 eu_ai_label_variant
:align: left, center, right left
:class: Extra CSS classes
:name: A name to cross-reference the label with, using :ref: with explicit text, e.g. :ref:`the summary label <summary-label>`

Role

Use the role to put a label inline:

This paragraph was :ai-label:`generated`.

Add a variant after the kind, and put text before it in angle brackets, as with links:

This summary was :ai-label:`generated white`.

:ai-label:`Paragraph written with <basic>`

:ai-label:`Illustrations modified with AI <modified black-50>`

Text goes in the same place as with the directive, but it can't contain markup. Without text, the role uses eu_ai_label_texts, and without a variant it uses eu_ai_label_variant.

In MyST Markdown, use {ai-label}`Paragraph written with <basic>`.

Page labels

To label a whole page, set ai-label in the page's metadata. The label goes at the top of the page, under its title. The value is a kind, optionally followed by a variant, as with the role.

:ai-label: generated

My page
=======

In MyST Markdown, use front matter:

---
ai-label: modified white
---

# My page

To label every page, set eu_ai_label_page. A page can still set its own label, or opt out with :ai-label: none.

eu_ai_label_page = "generated"

Page labels use the text from eu_ai_label_texts, if any. For other text, or to put a label somewhere else on the page, use the directive.

Configuration

These values go in conf.py:

Setting Default Description
eu_ai_label_variant "auto" Default colour variant. auto uses black in light mode and white in dark mode, using prefers-color-scheme
eu_ai_label_size "2.5em" Icon height for directive labels, as any CSS length. The icons have wide margins built in, so the visible mark is smaller than this
eu_ai_label_inline_size "1.75em" Icon height for role labels. It's smaller so that labels in running text don't stretch the line as much
eu_ai_label_texts {} Text to show next to each kind's icon, for example {"generated": "Généré par IA"}
eu_ai_label_page None A label for every page, such as "generated" or "modified white". See Page labels
eu_ai_label_latex_size "2.5em" Icon height for directive labels in LaTeX output, as a LaTeX length
eu_ai_label_latex_inline_size "1.75em" Icon height for role labels in LaTeX output, as a LaTeX length

auto follows the reader's operating system or browser setting. It also follows a theme's own light/dark switch if the theme sets a data-theme="light" or data-theme="dark" attribute on <html> or <body>, as Furo, PyData and Book do. For other themes with a switch, set a fixed variant.

The extension also adds a small stylesheet, _static/eu_ai_label/eu_ai_label.css. Labels have the CSS classes eu-ai-label, eu-ai-label-{kind}, and either eu-ai-label-block with eu-ai-label-align-{align}, or eu-ai-label-inline.

Other output formats

The icons appear in HTML output (including EPUB) and LaTeX/PDF output. LaTeX uses the black variant for auto, since print has no dark mode, and ignores :class:.

Other builders, such as man and plain text, show the label as text instead: the label text if you set any, including its markup (with "AI" after it for basic), otherwise what the icon says.

Translation

Text from the directive's :text: option is included in the gettext catalogues, so you can translate it like any other text, markup included. Text from eu_ai_label_texts isn't, because you can set that per language in conf.py. The alt text always says what the icon says, so it isn't translated either.

Accessibility

The Commission's guidance encourages accessible labels. The extension follows it in these ways:

  • Each icon's alt text is what the icon says: "AI", "AI-generated" or "AI-modified". This does not change when you add text, so basic with "Summary generated with" reads as "Summary generated with AI".
  • Any label text is real HTML text, so screen readers can read it and it scales with the reader's font size.
  • The icon heights are in em by default, so they scale with the text too.

Placement

The Commission's guidance says a label should be visible no later than the moment a reader first sees the content. It should also not be covered by other page elements. In practice, put the directive at the top of the page or section it applies to, or use page labels. For the full placement specifications, see Section 2 of the Code of Practice.

Licence

This project's code is under the MIT licence. See LICENSE. The icons are published by the European Commission, which says they are "made publicly available for everyone to use freely, without the need for attribution". This package includes the SVG files unmodified, apart from their file names, and PDF conversions of them for LaTeX output.

Development

make bootstrap  # Install dependencies with uv
make            # check, then test
make check      # Format check, lint and type check
make test       # Tests, with a 100% coverage requirement
make fix        # Auto-format and apply lint fixes
make docs       # Build the showcase site into docs/_build/html
make icons      # Regenerate the PDF icons for LaTeX from the SVGs

Releasing

The version comes from git tags, so there's nothing to bump. To release, create a GitHub Release with a new tag on main named v followed by the version (e.g. v0.2.0). Pushing the tag runs the publish workflow, which builds the package and uploads it to PyPI.

Metadata

Release files for sphinx-eu-ai-label 1.0.0

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

Source distribution (sdist)

Source distribution for sphinx-eu-ai-label 1.0.0
File Size Uploaded Provenance Actions
sphinx_eu_ai_label-1.0.0.tar.gz 124.2 kB Without provenance Details for sphinx_eu_ai_label-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sphinx-eu-ai-label 1.0.0
File Interpreter ABI Platform Actions
sphinx_eu_ai_label-1.0.0-py3-none-any.whl Python 3 none any Details for sphinx_eu_ai_label-1.0.0-py3-none-any.whl

Total release size: 202.5 kB

Release files / sphinx_eu_ai_label-1.0.0.tar.gz

Download URL sphinx_eu_ai_label-1.0.0.tar.gz
Size 124.2 kB
Tags Source
SHA-256 checksum
How to use checksums
5849f30943edfdadc526eb93fb3e16a157658b7d23396b2d55cbdf1bc2510b67
BLAKE2b-256 checksum
How to use checksums
6a610385bcf3ed372ba58ac9074a34b92d69e29e26e5c33064fbba9b664751bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / sphinx_eu_ai_label-1.0.0-py3-none-any.whl

Download URL sphinx_eu_ai_label-1.0.0-py3-none-any.whl
Size 78.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
10b443e20f6f5bb94006389b75b8d817c0fccdbb69d7916481ae7e14c217e501
BLAKE2b-256 checksum
How to use checksums
898ffa4ad1062650ad2777209bb3378994ed727e60af0ca8be4e138b5a607cfc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for sphinx-eu-ai-label 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

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