{"id":1891,"library":"accessible-pygments","title":"Accessible Pygments Styles","description":"A collection of accessible Pygments styles, currently at version 0.0.5. It provides themes that meet WCAG 2.1 color contrast requirements, aiming to make syntax highlighting more inclusive for users with low vision or color blindness. The library is actively maintained with regular minor releases adding new themes and improvements.","status":"active","version":"0.0.5","language":"en","source_language":"en","source_url":"https://github.com/Quansight-Labs/accessible-pygments","tags":["accessibility","pygments","syntax highlighting","themes","WCAG"],"install":[{"cmd":"pip install accessible-pygments","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"Provides the core syntax highlighting engine that accessible-pygments extends with new styles.","package":"Pygments"}],"imports":[{"note":"Importing the package registers its styles with Pygments, making them available by name. You do not typically import specific style classes directly for usage.","symbol":"accessible_pygments","correct":"import accessible_pygments"}],"quickstart":{"code":"from pygments import highlight\nfrom pygments.lexers import PythonLexer\nfrom pygments.formatters import HtmlFormatter\nimport accessible_pygments # This registers the styles\n\ncode_to_highlight = \"\"\"\ndef greet(name):\n    print(f\"Hello, {name}!\")\n\ngreet(\"World\")\n\"\"\"\n\n# Choose an accessible style, e.g., 'a11y-light', 'github-dark-colorblind'\nstyle_name = 'a11y-light'\n\n# Create an HTML formatter with the chosen accessible style\nformatter = HtmlFormatter(style=style_name, full=True, encoding='utf-8')\n\n# Highlight the code\nhighlighted_code = highlight(\n    code_to_highlight,\n    PythonLexer(),\n    formatter\n)\n\n# The highlighted_code is now a bytes object (due to encoding='utf-8' in full=True mode)\n# Decode to string if you want to print or save to a text file\nprint(highlighted_code.decode('utf-8'))\n\n# To save to an HTML file (example)\n# with open(\"highlighted_code.html\", \"wb\") as f:\n#     f.write(highlighted_code)","lang":"python","description":"This example demonstrates how to highlight Python code using the `a11y-light` style from `accessible-pygments`. The key is to import `accessible_pygments` to register its styles, then refer to the style by its string name when creating a Pygments formatter. The `full=True` option generates a complete HTML document including the stylesheet."},"warnings":[{"fix":"Upgrade to version 0.0.3 or newer to benefit from WCAG 2.1 compliant color contrast. Review your applications to ensure the new color schemes meet your visual and accessibility requirements.","message":"Version 0.0.3 included critical fixes to the highlighting colors across all themes. Users upgrading from versions prior to 0.0.3 should expect visual changes in their highlighted code, as older versions may have had incorrect or less accessible color contrasts.","severity":"breaking","affected_versions":"<0.0.3"},{"fix":"Ensure `accessible-pygments` is in your documentation's dependencies. In your `conf.py`, set `pygments_style = \"your-accessible-style-name\"`.","message":"When using `accessible-pygments` styles in Sphinx documentation, the style is specified as a string in `conf.py` (e.g., `pygments_style = \"a11y-light\"`). Do not attempt to import a Python class for the style directly into `conf.py`. The `accessible-pygments` package must be installed in the Sphinx environment.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always use the string name of the desired accessible style when initializing Pygments formatters.","message":"Pygments styles are referenced by their string names (e.g., `'a11y-light'`) in `HtmlFormatter(style='...')`. Do not attempt to directly import and pass a style class from `accessible_pygments` to the formatter (e.g., `HtmlFormatter(style=A11yLight)`). The package automatically registers these names upon import.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}