PHPackages                             ramsey/pygments - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. ramsey/pygments

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

ramsey/pygments
===============

A PHP wrapper for Pygments, the Python syntax highlighter, forked from kzykhys/pygments.

3.0.0(1y ago)103.1k6[1 PRs](https://github.com/ramsey/pygments/pulls)3MITPHPPHP ^8.2CI passing

Since Dec 19Pushed 7mo ago1 watchersCompare

[ Source](https://github.com/ramsey/pygments)[ Packagist](https://packagist.org/packages/ramsey/pygments)[ RSS](/packages/ramsey-pygments/feed)WikiDiscussions main Synced today

READMEChangelog (6)Dependencies (17)Versions (9)Used By (3)

ramsey/pygments
===============

[](#ramseypygments)

 **A PHP wrapper for Pygments, the Python syntax highlighter.**

 [![Source Code](https://camo.githubusercontent.com/c1596056c236faafceeacc36d543f0e078a05965ed6ca8e4ae8dbc18e6e73d77/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f736f757263652d72616d7365792f7079676d656e74732d626c75652e7376673f7374796c653d666c61742d737175617265)](https://github.com/ramsey/pygments) [![Download Package](https://camo.githubusercontent.com/89367b3d910db2945440241439509b2b3e4312c9f38605ec1d27f970f0cf18a4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f72616d7365792f7079676d656e74732e7376673f7374796c653d666c61742d737175617265266c6162656c3d72656c65617365)](https://packagist.org/packages/ramsey/pygments) [![PHP Programming Language](https://camo.githubusercontent.com/b83add7460c6d0479b91f1cb95f8b464eb82e595950ae894e4df7bac6309de2c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f72616d7365792f7079676d656e74732e7376673f7374796c653d666c61742d73717561726526636f6c6f72423d253233383839324246)](https://php.net) [![Read License](https://camo.githubusercontent.com/dba3850f4807df837a83c5819fb1d38c7f368e1730813a13d0e97f265eda43ae/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f72616d7365792f7079676d656e74732e7376673f7374796c653d666c61742d73717561726526636f6c6f72423d6461726b6379616e)](https://github.com/ramsey/pygments/blob/main/LICENSE) [![Build Status](https://camo.githubusercontent.com/3578824daeafb5a810c479aea673ab0d1613c0259fc3849c3bbd31ba0abf4be7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f72616d7365792f7079676d656e74732f636f6e74696e756f75732d696e746567726174696f6e2e796d6c3f6272616e63683d6d61696e266c6f676f3d676974687562267374796c653d666c61742d737175617265)](https://github.com/ramsey/pygments/actions/workflows/continuous-integration.yml) [![Codecov Code Coverage](https://camo.githubusercontent.com/86c6cf67894af097ed3943a27d628c6151b93b863ff81eab132bdb2a1e5bed5d/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f67682f72616d7365792f7079676d656e74733f6c6162656c3d636f6465636f76266c6f676f3d636f6465636f76267374796c653d666c61742d737175617265)](https://codecov.io/gh/ramsey/pygments)

About
-----

[](#about)

ramsey/pygments is a PHP wrapper for [Pygments](https://pygments.org), the Python syntax highlighter, forked from the [Pygments.php](https://github.com/kzykhys/Pygments.php) project.

This project adheres to a [code of conduct](CODE_OF_CONDUCT.md). By participating in this project and its community, you are expected to uphold this code.

Installation
------------

[](#installation)

Install this package as a dependency using [Composer](https://getcomposer.org).

```
composer require ramsey/pygments
```

### Requirements

[](#requirements)

- PHP 8.2 or greater
- Python
- Pygments (`pip install Pygments`)

Python and Pygments versions tested:

Pygments:2.172.182.19Python 3.11✔✔✔Python 3.12✔✔✔Python 3.13✔✔✔Python 3.14✔✔✔Note

ramsey/pygments will likely work on other versions of Python and Pygments, but the versions tested against are limited to keep the GitHub Actions job matrix at a reasonable size. If you encounter a version of Python or Pygments that does not work, please [open an issue](https://github.com/ramsey/pygments/issues).

Usage
-----

[](#usage)

### Highlight source code

[](#highlight-source-code)

```
use Ramsey\Pygments\Pygments;

$pygments = new Pygments();
$html = $pygments->highlight(file_get_contents('index.php'), 'php', 'html');
$console = $pygments->highlight('package main', 'go', 'ansi');
```

### Generate CSS

[](#generate-css)

```
use Ramsey\Pygments\Pygments;

$pygments = new Pygments();
$css = $pygments->getCss('monokai');
$prefixedCss = $pygments->getCss('default', '.syntax');
```

### Guess lexer name

[](#guess-lexer-name)

```
use Ramsey\Pygments\Pygments;

$pygments = new Pygments();
$lexer = $pygments->guessLexer('foo.rb'); // ruby
```

### Get a list of lexers/formatters/styles

[](#get-a-list-of-lexersformattersstyles)

```
use Ramsey\Pygments\Pygments;

$pygments = new Pygments();
$lexers = $pygments->getLexers()
$formatters = $pygments->getFormatters();
$styles = $pygments->getStyles();
```

### Set a custom `pygmentize` path

[](#set-a-custom-pygmentize-path)

```
use Ramsey\Pygments\Pygments;

$pygments = new Pygments('/path/to/pygmentize');
```

Contributing
------------

[](#contributing)

Contributions are welcome! To contribute, please familiarize yourself with [CONTRIBUTING.md](CONTRIBUTING.md).

Coordinated Disclosure
----------------------

[](#coordinated-disclosure)

Keeping user information safe and secure is a top priority, and we welcome the contribution of external security researchers. If you believe you've found a security issue in software that is maintained in this repository, please read [SECURITY.md](SECURITY.md) for instructions on submitting a vulnerability report.

Copyright and License
---------------------

[](#copyright-and-license)

The ramsey/pygments library is copyright © [Ben Ramsey](https://benramsey.com)and licensed for use under the terms of the MIT License (MIT).

ramsey/pygments is a fork of [Pygments.php](https://github.com/kzykhys/Pygments.php). The Pygments.php library is copyright © [Kazuyuki Hayashi](https://github.com/kzykhys)and licensed for use under the terms of the MIT License (MIT).

Please see [LICENSE](LICENSE) for more information.

###  Health Score

50

—

FairBetter than 95% of packages

Maintenance53

Moderate activity, may be stable

Popularity29

Limited adoption so far

Community23

Small or concentrated contributor base

Maturity81

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 71.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~580 days

Recently: every ~725 days

Total

6

Last Release

482d ago

Major Versions

1.0.1 → 2.0.02021-03-07

2.0.2 → 3.0.02025-03-07

PHP version history (4 changes)1.0.0PHP ^5.6 || ^7.0

1.0.1PHP ^5.5 || ^7.0

2.0.0PHP ^7.3 || ^8.0

3.0.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/f514481fa9cfdfd5dbcaccb3e5b480f18ea05ebf331cddf9b1c5a2a96a78fef5?d=identicon)[ramsey](/maintainers/ramsey)

---

Top Contributors

[![ramsey](https://avatars.githubusercontent.com/u/42941?v=4)](https://github.com/ramsey "ramsey (86 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (11 commits)")[![kzykhys](https://avatars.githubusercontent.com/u/1751547?v=4)](https://github.com/kzykhys "kzykhys (9 commits)")[![nicwortel](https://avatars.githubusercontent.com/u/1055691?v=4)](https://github.com/nicwortel "nicwortel (6 commits)")[![Krinkle](https://avatars.githubusercontent.com/u/156867?v=4)](https://github.com/Krinkle "Krinkle (2 commits)")[![DanielEScherzer](https://avatars.githubusercontent.com/u/179652704?v=4)](https://github.com/DanielEScherzer "DanielEScherzer (1 commits)")[![thomasrockhu](https://avatars.githubusercontent.com/u/4213028?v=4)](https://github.com/thomasrockhu "thomasrockhu (1 commits)")[![jayvdb](https://avatars.githubusercontent.com/u/15092?v=4)](https://github.com/jayvdb "jayvdb (1 commits)")[![JeroenDeDauw](https://avatars.githubusercontent.com/u/146040?v=4)](https://github.com/JeroenDeDauw "JeroenDeDauw (1 commits)")[![MatmaRex](https://avatars.githubusercontent.com/u/160413?v=4)](https://github.com/MatmaRex "MatmaRex (1 commits)")[![sroze](https://avatars.githubusercontent.com/u/804625?v=4)](https://github.com/sroze "sroze (1 commits)")

---

Tags

highlightphppygmentizepygmentssyntaxhighlightsyntaxpygments

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/ramsey-pygments/health.svg)

```
[![Health](https://phpackages.com/badges/ramsey-pygments/health.svg)](https://phpackages.com/packages/ramsey-pygments)
```

###  Alternatives

[matomo/matomo

Matomo is the leading Free/Libre open analytics platform

21.7k38.9k](/packages/matomo-matomo)[scrivo/highlight.php

Server side syntax highlighter that supports 185 languages. It's a PHP port of highlight.js

71346.6M110](/packages/scrivo-highlightphp)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

751291.4k43](/packages/civicrm-civicrm-core)[spatie/laravel-export

Create a static site bundle from a Laravel app

674146.0k6](/packages/spatie-laravel-export)[illuminate/process

The Illuminate Process package.

44869.2k99](/packages/illuminate-process)[easybook/geshi

GeSHi - Generic Syntax Highlighter. This is an unmodified port of GeSHi project code found on SourceForge.

221.1M10](/packages/easybook-geshi)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
