Skip to main content

Installation

pip install fastpylight

fastpylight is a small Python/Rust wrapper around Lumis, a Tree-sitter syntax highlighter with Neovim themes. Language names, token scopes, and theme names follow Lumis.

Python

from fastpylight import highlight, highlight_spans, guess, theme_css

code = "def f(x):\n    return x + 1\n"

# Output for the CSS Highlight API.
html = highlight(code, "python")

# Static span output.
spans = highlight_spans(code, "python")

# CSS rules for the span output.
css = theme_css("github_light", "pre code")

highlight returns HTML with token ranges in UTF-16 code units, for use with the CSS Highlight API:

<hl-code toks='[[0,3,"keyword"],[4,5,"function"],[6,7,"variable"],[14,20,"keyword"],[21,22,"variable"],[23,24,"operator"],[25,26,"number"]]'><pre><code>def f(x):
    return x + 1
</code></pre></hl-code>

highlight_spans returns normal HTML spans:

<pre><code><span class="hl-keyword">def</span> <span class="hl-function">f</span>(<span class="hl-variable">x</span>):
    <span class="hl-keyword">return</span> <span class="hl-variable">x</span> <span class="hl-operator">+</span> <span class="hl-number">1</span>
</code></pre>

The exact classes depend on Lumis scopes. A complete GitHub Light CSS example for both output modes is in docs/github_light.css.

Languages

The default language set enables Lumis web, web-extra, system, and backend bundles, plus R, Julia, PowerShell, Lua, Swift, MATLAB, Perl, Pascal, Fortran, and Objective-C.

Markdown is treated as quotation: fenced code bodies and other injected languages flatten to the markup.raw.block scope instead of being highlighted as the embedded language, so markdown source specimens read as markdown. Markdown's own structure (headings, fence markers, info strings, inline code) keeps its scopes.

languages() lists every available name. The highlighting functions need an exact language name and raise ValueError on an unknown one. Use "plaintext" for un-highlighted output:

highlight(code, "plaintext")  # toks='[]', no tokens

To detect a language instead of specifying one, use guess, which takes the code plus an optional hint (a name, extension, or filename) and falls back to "plaintext" when nothing matches:

guess("fn main() {}", "rs")        # 'rust'  (extension hint)
guess("#!/usr/bin/env python\n")   # 'python' (shebang)
guess("just some prose")           # 'plaintext' (no match)

highlight(code, guess(code))       # detect, then highlight

CSS Highlight API

The highlight function is for browser code that applies token ranges with the CSS Highlight API. component_js() returns the reference component:

class HlCode extends HTMLElement {
  connectedCallback(){
    if(!CSS.highlights) return;
    setTimeout(() => {
      const d=this.getAttribute('toks'); if(!d) return;
      const tn=this.querySelector('code').firstChild, toks=JSON.parse(d);
      this._ranges=[];
      toks.forEach(([s,e,k])=>{
        const r=new Range(); r.setStart(tn,s); r.setEnd(tn,e);
        const h=CSS.highlights.get(k)||new Highlight();
        h.add(r); CSS.highlights.set(k,h);
        this._ranges.push([r,k]);
      });
      this.removeAttribute('toks');
    }, 0);
  }
  disconnectedCallback(){
    if(!this._ranges) return;
    this._ranges.forEach(([r,k])=>{
      const h=CSS.highlights.get(k); if(h) h.delete(r);
    });
    this._ranges=null;
  }
}
if(!customElements.get('hl-code')) customElements.define('hl-code',HlCode);

highlight needs ::highlight(...) rules. highlight_spans needs class rules. docs/github_light.css includes both for the default hl- prefix.

You can generate CSS at runtime:

highlight_css = theme_css("github_light")
span_css = theme_css("github_light", "pre code")

For non-CSS consumers (e.g. document converters), theme_colors("github_light") returns the same theme as data: a dict of dotted scope names (including normal, which the CSS omits) to {'fg', 'bg', 'bold', 'italic', 'underline', 'strikethrough'}.

Release files for fastpylight 0.1.18

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

Source distribution (sdist)

Source distribution for fastpylight 0.1.18
File Size Uploaded
fastpylight-0.1.18.tar.gz 28.9 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for fastpylight 0.1.18
File
fastpylight-0.1.18-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.17+ x86-64 Details
fastpylight-0.1.18-cp313-cp313-macosx_11_0_arm64.whl CPython 3.13 CPython 3.13 macOS 11.0+ ARM64 Details
fastpylight-0.1.18-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ x86-64 Details
fastpylight-0.1.18-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details
fastpylight-0.1.18-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.17+ x86-64 Details
fastpylight-0.1.18-cp311-cp311-macosx_11_0_arm64.whl CPython 3.11 CPython 3.11 macOS 11.0+ ARM64 Details
fastpylight-0.1.18-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.17+ x86-64 Details
fastpylight-0.1.18-cp310-cp310-macosx_11_0_arm64.whl CPython 3.10 CPython 3.10 macOS 11.0+ ARM64 Details

Total release size: 65.6 MB

Release files / fastpylight-0.1.18.tar.gz

Download URL fastpylight-0.1.18.tar.gz
Size 28.9 kB
Tags Source
SHA-256 checksum
How to use checksums
efa244a2ebe7296684658db68c0ddcc97976701e1551861a1c6a1fec0857565a
BLAKE2b-256 checksum
How to use checksums
873a8977783f6bfd2b0718912e3cb89fd0a175f1cc9491be09c537ea4d6e1599
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.7 {"installer":{"name":"uv","version":"0.12.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 / fastpylight-0.1.18-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL fastpylight-0.1.18-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 8.1 MB
Tags CPython 3.13 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
10c4c7c9ad50d1128f265e1c13dd609b446fde7d449556cfe2dc94e00e5e5da1
BLAKE2b-256 checksum
How to use checksums
f1c0d38a4df0608a446f7f9c3d36d6399d7f7caccc0eb2922a60b5636d6d419c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.7 {"installer":{"name":"uv","version":"0.12.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 / fastpylight-0.1.18-cp313-cp313-macosx_11_0_arm64.whl

Download URL fastpylight-0.1.18-cp313-cp313-macosx_11_0_arm64.whl
Size 8.3 MB
Tags CPython 3.13 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
53ac9b80592d57e87423dcc8b0bb71846f0424a1779f63298485366a2a202e9a
BLAKE2b-256 checksum
How to use checksums
688674aabdf9712b65200ac290f5e594f7953b542569aaf8ce22770aae13a3f7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.7 {"installer":{"name":"uv","version":"0.12.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 / fastpylight-0.1.18-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL fastpylight-0.1.18-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 8.1 MB
Tags CPython 3.12 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
05c15eb36d8ac53902c37913dec6586ad5a59f09795c7827788f1cea12437aeb
BLAKE2b-256 checksum
How to use checksums
4604884573f207575b150de93cc3b5a49aa65c219fa1457b46b9e36a650ecbca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.7 {"installer":{"name":"uv","version":"0.12.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 / fastpylight-0.1.18-cp312-cp312-macosx_11_0_arm64.whl

Download URL fastpylight-0.1.18-cp312-cp312-macosx_11_0_arm64.whl
Size 8.3 MB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
b8fc43cd7043906e24dd2b8598fa478816abaf9cfb538f3365e943920df6ad62
BLAKE2b-256 checksum
How to use checksums
bfb9eaa416a602de850785e5122217046d60ee406e08a241ad4fd3aefb7c2f78
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.7 {"installer":{"name":"uv","version":"0.12.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 / fastpylight-0.1.18-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL fastpylight-0.1.18-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 8.1 MB
Tags CPython 3.11 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
a39197f56f81a0d798a9be37f17aca356a4c2d0e24809e2794f85d9ae2fb6c87
BLAKE2b-256 checksum
How to use checksums
eef292d8b24089a3d383595d1772e825c35d54f634b90d0362cf4d7a6be9afbd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.7 {"installer":{"name":"uv","version":"0.12.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 / fastpylight-0.1.18-cp311-cp311-macosx_11_0_arm64.whl

Download URL fastpylight-0.1.18-cp311-cp311-macosx_11_0_arm64.whl
Size 8.3 MB
Tags CPython 3.11 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
944880eaedda8f78caf0977f48158ce47576c5767ab33272674ec8ecbe51f2e4
BLAKE2b-256 checksum
How to use checksums
91d6d4434b53d2678bbb26555f7f1672e64cc1788b223debbd2851dcb027825b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.7 {"installer":{"name":"uv","version":"0.12.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 / fastpylight-0.1.18-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL fastpylight-0.1.18-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 8.1 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
714fe9ec5c5fdd5254d7468d81888bc1e1ead5c810f83815b0a3f3c38344b7cd
BLAKE2b-256 checksum
How to use checksums
146012ab142fb3b492770a61ab7ed2a14787a3eebe777f25cc8e1916b1c5d4e1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.7 {"installer":{"name":"uv","version":"0.12.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 / fastpylight-0.1.18-cp310-cp310-macosx_11_0_arm64.whl

Download URL fastpylight-0.1.18-cp310-cp310-macosx_11_0_arm64.whl
Size 8.3 MB
Tags CPython 3.10 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
0fce5faa4df532f5b5dcf47882c630aa29f5bd76ec46a438e29563c1561f6dc8
BLAKE2b-256 checksum
How to use checksums
e79248b1a6cec95af6272c015824f7323dcea2648cde828c8883e1d5ba3e99ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.7 {"installer":{"name":"uv","version":"0.12.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 history Release notifications | RSS feed

This release

0.1.18 This release

9 release files

0.1.17

9 release files

0.1.16

9 release files

0.1.15

9 release files

0.1.14

9 release files

0.1.13

9 release files

0.1.12

9 release files

0.1.11

9 release files

0.1.10

9 release files

0.1.9

9 release files

0.1.8

9 release files

0.1.7

9 release files

0.1.6

9 release files

0.1.5

9 release files

0.1.4

9 release files

0.1.3

9 release files

0.1.2

9 release files

0.1.1

9 release files

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