{
 "kind": "tool",
 "slug": "pygments",
 "path": "tools/pygments/",
 "name": "Pygments",
 "maker": null,
 "density": "full",
 "crumbs": [
  [
   "Tools",
   "tools/"
  ],
  [
   "Markdown, editors and content",
   "tools/content-editors/"
  ]
 ],
 "lead": "Colored code for pages, docs and terminals.",
 "chips": [
  {
   "label": "Markdown, editors and content",
   "path": "tools/content-editors/"
  },
  {
   "label": "PYPI"
  }
 ],
 "primary": {
  "label": "Copy install command",
  "copy": "pip install pygments"
 },
 "links": [
  {
   "label": "GitHub",
   "href": "https://github.com/pygments/pygments"
  },
  {
   "label": "Website",
   "href": "https://pygments.org"
  }
 ],
 "track": "New versions, deprecation and license changes on your dashboard",
 "verdicts": [
  {
   "key": "license",
   "label": "License",
   "value": "BSD-2-Clause",
   "status": "yes",
   "sub": "Use it in paid apps",
   "quote": "Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met",
   "note": "Keep the copyright notice and license text with the copies you ship.",
   "src": "https://github.com/pygments/pygments/blob/master/LICENSE"
  },
  {
   "key": "maint",
   "label": "Maintained",
   "value": "Maintained",
   "status": "yes",
   "sub": "Last change Sep 27, 2026",
   "note": "Latest GitHub release Aug 17, 2026. ",
   "src": "https://github.com/pygments/pygments"
  },
  {
   "key": "pop",
   "label": "Used by agents' projects",
   "value": "61 projects",
   "status": "info",
   "sub": "#11 of 149 in its category",
   "note": "Dependency in 61 public GitHub projects set up for AI coding agents that we scanned (1.0%).",
   "src": null
  },
  {
   "key": "agent",
   "label": "Agent access",
   "value": "Install only",
   "status": "info",
   "sub": null,
   "note": "Agent skills for this library in the skills catalog; community skills are written by others, read them before you install.",
   "src": null
  }
 ],
 "vfoot": "From the package registry and GitHub, checked daily; card checked Nov 11, 2026.",
 "blocks": [
  {
   "id": "overview",
   "nav": "Overview",
   "h2": "What Pygments does",
   "parts": [
    {
     "t": "prose",
     "text": "Pygments is a free Python library that colors program code the way code editors do. Your Python app or docs site gives it a code snippet and the language, and gets back colored HTML, terminal text or other formats. It knows about 600 languages and file formats."
    },
    {
     "t": "h3",
     "text": "What people build with it"
    },
    {
     "t": "uses",
     "items": [
      {
       "title": "Code samples on a blog or docs site",
       "text": "A site built in Python shows code blocks in articles with colors and line numbers instead of plain gray text.",
       "idea": false
      },
      {
       "title": "Colored output in a command-line tool",
       "text": "A Python script that prints code, logs or config files shows them in color in the terminal.",
       "idea": false
      },
      {
       "title": "Code examples in project documentation",
       "text": "Documentation built with Sphinx or Material for MkDocs colors its code examples with Pygments.",
       "idea": false
      },
      {
       "title": "Code in printed reports and papers",
       "text": "A report generator puts colored code into LaTeX or RTF files for PDFs and word processors, not only web pages.",
       "idea": false
      },
      {
       "title": "Code in answers from an AI chat",
       "text": "A Python chat app colors the code blocks in model answers on the server, with a time limit for each snippet.",
       "idea": true
      },
      {
       "title": "Code pictures for social posts",
       "text": "Turn a short snippet into a PNG to post where code blocks are not supported; this needs the Pillow library too.",
       "idea": true
      }
     ]
    }
   ]
  },
  {
   "id": "popularity",
   "nav": "Popularity",
   "h2": "Pygments popularity",
   "parts": [
    {
     "t": "stats",
     "items": [
      {
       "n": "71",
       "of": "/ 100",
       "l": "Gid Score, #337 overall"
      },
      {
       "n": "287M",
       "l": "downloads a week, pypi"
      },
      {
       "n": "2,226",
       "l": "GitHub stars"
      },
      {
       "n": "61",
       "l": "agent projects use it"
      }
     ]
    },
    {
     "t": "small",
     "text": "Gid Score measures public popularity and activity, not quality.",
     "link": "How the Gid Score is calculated",
     "path": "tools/top/"
    }
   ]
  },
  {
   "id": "usage",
   "nav": "How it is used",
   "h2": "How Pygments is used",
   "parts": [
    {
     "t": "list",
     "items": [
      "Pygments is a dependency in 61 of the 6,258 public GitHub projects set up for AI coding agents that we scanned (3.8% of the 1,623 Python ones), #11 of 149 in markdown, editors and content.",
      "Counting the projects our scan samples by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750), it appears in 1,109; those are left out of every share on this page.",
      "Projects that use it most often also use Pydantic (78.7%), Click (77.0%), Requests (73.8%)."
     ]
    },
    {
     "t": "h3",
     "text": "By coding agent"
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "38 projects, 1.3%",
       "v": "GitHub Copilot",
       "path": "agents/github-copilot/"
      },
      {
       "l": "34 projects, 1.0%",
       "v": "Claude Code",
       "path": "agents/claude-code/"
      },
      {
       "l": "19 projects, 0.8%",
       "v": "Cursor",
       "path": "agents/cursor/"
      },
      {
       "l": "5 projects, 1.1%",
       "v": "Gemini CLI",
       "path": "agents/gemini-cli/"
      }
     ]
    },
    {
     "t": "h3",
     "text": "Often used with"
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "In 78.7% of its projects",
       "v": "Pydantic",
       "path": "tools/pydantic/"
      },
      {
       "l": "In 77.0% of its projects",
       "v": "Click",
       "path": "tools/click-py/"
      },
      {
       "l": "In 73.8% of its projects",
       "v": "Requests",
       "path": "tools/requests-py/"
      },
      {
       "l": "In 72.1% of its projects",
       "v": "packaging",
       "path": "tools/packaging/"
      },
      {
       "l": "In 72.1% of its projects",
       "v": "PyYAML",
       "path": "tools/pyyaml/"
      }
     ]
    }
   ]
  },
  {
   "id": "more",
   "nav": null,
   "spy_as": "usage",
   "h2": "More about Pygments",
   "parts": [
    {
     "t": "more",
     "items": [
      {
       "title": "More in Markdown, editors and content",
       "path": "tools/content-editors/",
       "items": [
        {
         "text": "react-markdown",
         "path": "tools/react-markdown/"
        },
        {
         "text": "remark-gfm",
         "path": "tools/remark-gfm/"
        },
        {
         "text": "Marked",
         "path": "tools/marked/"
        },
        {
         "text": "Jinja2",
         "path": "tools/jinja2/"
        },
        {
         "text": "gray-matter",
         "path": "tools/gray-matter/"
        },
        {
         "text": "Tiptap",
         "path": "tools/tiptap/"
        },
        {
         "text": "Shiki",
         "path": "tools/shiki/"
        },
        {
         "text": "highlight.js",
         "path": "tools/highlight-js/"
        }
       ]
      }
     ]
    }
   ]
  },
  {
   "id": "alternatives",
   "nav": "Alternatives",
   "h2": "Alternatives",
   "parts": [
    {
     "t": "alts",
     "items": [
      {
       "name": "Pygments",
       "me": true,
       "facts": [
        "BSD-2-Clause",
        "Gid 71",
        "287M/wk"
       ]
      },
      {
       "name": "Shiki",
       "why": "Pick Shiki for JavaScript sites that want code colored with the same grammars and themes as VS Code.",
       "path": "tools/shiki/",
       "facts": []
      },
      {
       "name": "highlight.js",
       "why": "Pick highlight.js to color code in the browser, with automatic language detection.",
       "path": "tools/highlight-js/",
       "facts": []
      },
      {
       "name": "PrismJS",
       "why": "Pick PrismJS for a small in-browser highlighter with plugins for line numbers and copy buttons.",
       "path": "tools/prismjs/",
       "facts": []
      }
     ],
     "more": "Compare Pygments with another tool",
     "more_path": "tools/compare/"
    }
   ]
  },
  {
   "id": "start",
   "nav": "Get started",
   "h2": "Get started",
   "parts": [
    {
     "t": "prompt",
     "text": "Use the Python library Pygments (pin Pygments==2.21.0, Python 3.9+) to turn code blocks into highlighted HTML with highlight(code, get_lexer_by_name(lang), HtmlFormatter()), fall back to TextLexer for unknown languages, and add the CSS from HtmlFormatter().get_style_defs('.highlight')."
    },
    {
     "t": "steps",
     "items": [
      {
       "text": "Install Pygments into your project's Python environment; it needs nothing else.",
       "code": "pip install Pygments",
       "src": "https://pygments.org/faq/"
      },
      {
       "text": "Pick a lexer for the language and a formatter for the output, then call highlight().",
       "code": "from pygments import highlight\nfrom pygments.lexers import PythonLexer\nfrom pygments.formatters import HtmlFormatter\n\ncode = 'print \"Hello World\"'\nprint(highlight(code, PythonLexer(), HtmlFormatter()))\n",
       "src": "https://pygments.org/docs/quickstart/"
      },
      {
       "text": "Make the stylesheet once and add it to your page, or the HTML stays uncolored.",
       "code": "print(HtmlFormatter().get_style_defs('.highlight'))",
       "src": "https://pygments.org/docs/quickstart/"
      }
     ]
    },
    {
     "t": "h3",
     "text": "Mistakes to avoid"
    },
    {
     "t": "mistakes",
     "items": [
      {
       "dont": "Inserting highlight(...) output into a page without any stylesheet",
       "fix": "Add HtmlFormatter(style=...).get_style_defs('.highlight') to your CSS, or use HtmlFormatter(noclasses=True) for HTML email",
       "why": "By default the HTML only carries short class names like k and s; the colors live in the stylesheet."
      },
      {
       "dont": "lexer = guess_lexer(snippet) for short chat or markdown code blocks",
       "fix": "Use the language tag from the code fence with get_lexer_by_name(), and fall back to TextLexer on ClassNotFound",
       "why": "Guessing scores every lexer on the text; in our run a four-line SQL query was guessed as scdoc."
      },
      {
       "dont": "Highlighting code that visitors paste, inside the web request, with no limit",
       "fix": "Cap the input size, run highlighting in a separate process with a timeout, and limit how many run at once",
       "why": "Some inputs make Pygments run for a very long time or use a lot of memory, which can take the server down."
      },
      {
       "dont": "Using ImageFormatter (PNG or JPG output) with only Pygments installed",
       "fix": "Install Pillow as well before using the image formatters",
       "why": "The image formatters draw with the Python Imaging Library, which Pygments does not install."
      }
     ]
    }
   ]
  },
  {
   "id": "faq",
   "nav": "Questions",
   "h2": "Questions",
   "parts": [
    {
     "t": "faq",
     "items": [
      {
       "q": "Why is my highlighted HTML still black and white?",
       "a": "The HTML uses class names; you also need the stylesheet from get_style_defs(), or noclasses=True for inline colors.",
       "evidence": {
        "url": "https://pygments.org/docs/quickstart/",
        "quote": "As you can see, Pygments uses CSS classes (by default, but you can change that) instead of inline styles in order to avoid outputting redundant style information over and over."
       }
      },
      {
       "q": "Can it figure out the language by itself?",
       "a": "It can guess from a file name or the text, but guessing short snippets is unreliable; pass the language when you know it.",
       "evidence": {
        "url": "https://pygments.org/docs/quickstart/",
        "quote": "If you don't know the content of the file, or you want to highlight a file whose extension is ambiguous, such as .html (which could contain plain HTML or some template tags), use these functions"
       }
      },
      {
       "q": "Can I use it from the command line?",
       "a": "Yes. The pygmentize command colors a file in the terminal or writes an HTML file.",
       "evidence": {
        "url": "https://pygments.org/docs/quickstart/",
        "quote": "This will produce a full HTML document with included stylesheet."
       }
      },
      {
       "q": "My security scanner flags a Pygments advisory. Am I at risk?",
       "a": "The project says the risk is slow processing of untrusted input in a service; a docs build that does not take user input is not exposed.",
       "evidence": {
        "url": "https://pygments.org/docs/security/",
        "quote": "Especially if you're using Pygments for your documentation and not wrapping it into a service, you are not vulnerable"
       }
      },
      {
       "q": "Which Python version does it need?",
       "a": "Pygments 2.21.0 needs Python 3.9 or newer.",
       "evidence": {
        "url": "https://pypi.org/pypi/pygments/json",
        "quote": "\"requires_python\":\">=3.9\""
       }
      }
     ]
    }
   ]
  }
 ],
 "glance": [
  [
   "Package",
   "pypi pygments"
  ],
  [
   "Category",
   "Markdown, editors and content"
  ],
  [
   "License",
   "BSD-2-Clause"
  ],
  [
   "Gid Score",
   "71.1"
  ],
  [
   "Rank in category",
   "#11 of 149"
  ],
  [
   "GitHub",
   "pygments/pygments"
  ],
  [
   "Last change",
   "Sep 27, 2026"
  ]
 ],
 "good": [
  "It has no time limit. Some unlucky input can make it run for a very long time, so code typed by strangers needs a timeout.",
  "It only colors code. It does not check code for mistakes or understand what the code does.",
  "It runs in Python. A site that colors code in the browser uses a JavaScript highlighter instead."
 ],
 "checked_line": "Read by AgentGid from 9 official pages, card checked Nov 11, 2026; numbers update daily.",
 "logo": "https://agentgid.com/media/avatars/pygments.png"
}