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", "hl-")

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

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. A minimal component looks like this:

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", "hl-")

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'}.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastpylight-0.1.13.tar.gz (23.8 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

fastpylight-0.1.13-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.3 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

fastpylight-0.1.13-cp313-cp313-macosx_11_0_arm64.whl (8.6 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

fastpylight-0.1.13-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.3 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

fastpylight-0.1.13-cp312-cp312-macosx_11_0_arm64.whl (8.6 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

fastpylight-0.1.13-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.3 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

fastpylight-0.1.13-cp311-cp311-macosx_11_0_arm64.whl (8.6 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

fastpylight-0.1.13-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.3 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

fastpylight-0.1.13-cp310-cp310-macosx_11_0_arm64.whl (8.6 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file fastpylight-0.1.13.tar.gz.

File metadata

  • Download URL: fastpylight-0.1.13.tar.gz
  • Upload date:
  • Size: 23.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","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}

File hashes

Hashes for fastpylight-0.1.13.tar.gz
Algorithm Hash digest
SHA256 a19c976056c4af6468461f3f013b7db9d8e2c8e4c586ace1c266053a3292ec21
MD5 1bc4fbc069412be5d8781ee5d6ac9b0d
BLAKE2b-256 429045f08f34ccd4f822fb399e5f05a9c52404352a7d06813cc946795c2ac5ca

See more details on using hashes here.

File details

Details for the file fastpylight-0.1.13-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

  • Download URL: fastpylight-0.1.13-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 8.3 MB
  • Tags: CPython 3.13, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","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}

File hashes

Hashes for fastpylight-0.1.13-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0f2ff9db78bf12a8fa01b1566ef488274ec8bb5c63a7ee5f4f5621aea1233e58
MD5 08ffb8fcbb106d1e5e5a47e1d04435e3
BLAKE2b-256 bcf49e95be9226144780f2eef003bbd91f755f655bab6fd44eba9b0139833818

See more details on using hashes here.

File details

Details for the file fastpylight-0.1.13-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

  • Download URL: fastpylight-0.1.13-cp313-cp313-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 8.6 MB
  • Tags: CPython 3.13, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","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}

File hashes

Hashes for fastpylight-0.1.13-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1093ff3912f0abd45e7c0a9f1c46b7489aa634e61d4d3b624be8f78d13f14ee0
MD5 d7dccf172eb895f296f1a2d28beac522
BLAKE2b-256 f8971ebd7f8e9fe7f953e81f89ef2fd4f1fe58d6f765775f97b9c16a8036b2ef

See more details on using hashes here.

File details

Details for the file fastpylight-0.1.13-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

  • Download URL: fastpylight-0.1.13-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 8.3 MB
  • Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","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}

File hashes

Hashes for fastpylight-0.1.13-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 178db34359862686f316a6f3b556fc76bc2a242cf539f94811bde3d0c7b7e076
MD5 96b726ca7309894afd72e0a779653945
BLAKE2b-256 ff688063349de0cc90f012599e5fc1fcea1bb84e114055cf6ee4e8ef0238377f

See more details on using hashes here.

File details

Details for the file fastpylight-0.1.13-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

  • Download URL: fastpylight-0.1.13-cp312-cp312-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 8.6 MB
  • Tags: CPython 3.12, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","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}

File hashes

Hashes for fastpylight-0.1.13-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 92c4d9a40ca7152454c190e401f22c169e621c03f9d6f9ebd27986d6b0e12533
MD5 10e57b674b1bf24ff0687b08ce517004
BLAKE2b-256 e60cd6396f82581bb5d9f629829ba685129a4fdf5fd6d70664dd2e1ea1e8767a

See more details on using hashes here.

File details

Details for the file fastpylight-0.1.13-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

  • Download URL: fastpylight-0.1.13-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 8.3 MB
  • Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","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}

File hashes

Hashes for fastpylight-0.1.13-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4138fd1706c3bac9bf2876a7670a2e12329b1d63afa4c5c0f2bbbe6891fa611a
MD5 69f3bed366b1c2e414f0b818e4b62f7b
BLAKE2b-256 d55e41955144701a34f3818694363ff953fa7fc4f45a8bcafb6980e0d736cf99

See more details on using hashes here.

File details

Details for the file fastpylight-0.1.13-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

  • Download URL: fastpylight-0.1.13-cp311-cp311-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 8.6 MB
  • Tags: CPython 3.11, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","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}

File hashes

Hashes for fastpylight-0.1.13-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e04f6eed69949a348bd14deb479a767625790a9745bdafdb81cb842b768d51ac
MD5 89cce8155a7cec0718d8089d8267eaaf
BLAKE2b-256 187ac92e9bb6b3ce31db0294b58ec20c155ebb819d9e75dbd79910b9f842f1a2

See more details on using hashes here.

File details

Details for the file fastpylight-0.1.13-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

  • Download URL: fastpylight-0.1.13-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 8.3 MB
  • Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","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}

File hashes

Hashes for fastpylight-0.1.13-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 01c5afa8cab05b3398740b1c1ea7ef61985c0c0efd7f61c55a6f02b4957bd9a8
MD5 cd8a4ccf878c2fb3eef6aba7015e3df0
BLAKE2b-256 fba635363f651a585c01b8a7568f89887f513a60d539a7e71509e3c1bc771685

See more details on using hashes here.

File details

Details for the file fastpylight-0.1.13-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

  • Download URL: fastpylight-0.1.13-cp310-cp310-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 8.6 MB
  • Tags: CPython 3.10, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","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}

File hashes

Hashes for fastpylight-0.1.13-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 37ae26016c67c2d177e5ac06691caeceaa4543911f70eac270a58e1c86563285
MD5 81b07546f7ab9ed9c10bdc7e29c5a816
BLAKE2b-256 78c7003244c122e67c15b89899c6bbcdcb0b0fa6f0b2ae7388c63f80dcd3965f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page