Skip to main content

pysyntect

Project License - MIT pypi version conda version download count Downloads PyPI status Linux build MacOS build Windows build

Copyright © 2020– Spyder Project Contributors

Overview

Python bindings for the Syntect library. Pysyntect provides a lightweight, fast engine to compute syntax highlighting using Sublime Text syntax definitions and TextMate theme definitions, which are shared by many editors.

Python example

Installing

To install pysyntect, you can use both conda or pip package managers:

# Using Conda (Recommended)
conda install pysyntect -c spyder-ide

# Using pip
pip install pysyntect

Dependencies

To compile pysyntect, you will require the latest stable/beta/nightly release of Rust, alongside Cargo. Also, it requires a Python distribution with its corresponding development headers. Finally, this project depends on the following Cargo crates:

  • PyO3: Library used to produce Python bindings from Rust code.
  • Syntect: Syntax highlighting library in Rust.
  • Maturin: Build system to build and publish Rust-based Python packages

Compilling locally

Besides Rust, you will require the latest version of maturin installed to compile this project locally:

pip install maturin toml

After installing those packages, it is possible to execute the following command to compile pysyntect:

maturin develop

In order to produce wheels, maturin build can be used instead. This project supports PEP517, thus pip can be used to install this package as well:

pip install -U .

Running tests

We use pytest to run tests as it follows (after calling maturin develop):

pytest -v syntect/tests

Package usage

Pysyntect provides utillities and functions for loading themes and syntax definitions, as well to highlight text strings. Pysyntect supports over 500 syntax language definitions across many TextMate theme definitions (not included as part of this package).

from syntect import (highlight, load_theme_folder,
                     load_default_syntax, load_syntax_folder,
                     escape_to_console)

# Load default syntax grammars
syntax = load_default_syntax()

# Load syntax grammars from a path
syntax = load_syntax_folder("path/to/a/folder/with/grammars")

# Languages supported by the syntax set
syntax.languages

# Load theme definitions from a path
themes = load_theme_folder("path/to/a/folder/with/themes")

# List of themes loaded
themes.themes

# Select a theme
theme = themes['<name_of_the_theme>']

# Load a file and syntax highlight it
with open('my_file.extension', 'r') as f:
    lines = f.read()

# Returns a list of styles to apply per token
color_ranges = highlight(lines, 'extension', syntax, theme)

# Get background/foreground colors by token
style, token = color_ranges[0]

background = style.background
foreground = style.foreground

components = ('r', 'g', 'b', 'a')
bg_red, bg_green, bg_blue, bg_alpha = [getattr(background, c)
                                       for c in components]
fg_red, fg_green, fg_blue, fg_alpha = [getattr(foreground, c)
                                       for c in components]

# Preview syntax highlighing result to console
escape_to_console(color_ranges, display_bg=True)

Changelog

Please see our CHANGELOG file to learn more about our new features and improvements.

Contribution guidelines

We follow PEP8 and PEP257 for pure python packages and Rust to compile extensions. We use MyPy type annotations for all functions and classes declared on this package. Feel free to send a PR or create an issue if you have any problem/question.

Release files for pysyntect 0.3.0

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

Source distribution (sdist)

Source distribution for pysyntect 0.3.0
File Size Uploaded
pysyntect-0.3.0.tar.gz 3.3 MB Details

Built distributions (wheels)

Table of built distributions (wheels) for pysyntect 0.3.0
File
pysyntect-0.3.0-cp39-none-win_amd64.whl CPython 3.9 none Windows x86-64 Details
pysyntect-0.3.0-cp39-cp39-manylinux_2_24_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.24+ x86-64 Details
pysyntect-0.3.0-cp39-cp39-macosx_10_7_x86_64.whl CPython 3.9 CPython 3.9 macOS 10.7+ x86-64 Details
pysyntect-0.3.0-cp38-none-win_amd64.whl CPython 3.8 none Windows x86-64 Details
pysyntect-0.3.0-cp38-cp38-manylinux_2_24_x86_64.whl CPython 3.8 CPython 3.8 Linux glibc 2.24+ x86-64 Details
pysyntect-0.3.0-cp38-cp38-macosx_10_7_x86_64.whl CPython 3.8 CPython 3.8 macOS 10.7+ x86-64 Details
pysyntect-0.3.0-cp37-none-win_amd64.whl CPython 3.7 none Windows x86-64 Details
pysyntect-0.3.0-cp37-cp37m-manylinux_2_24_x86_64.whl CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.24+ x86-64 Details
pysyntect-0.3.0-cp37-cp37m-macosx_10_7_x86_64.whl CPython 3.7 CPython 3.7 pymalloc macOS 10.7+ x86-64 Details
pysyntect-0.3.0-cp36-none-win_amd64.whl CPython 3.6 none Windows x86-64 Details
pysyntect-0.3.0-cp36-cp36m-manylinux_2_24_x86_64.whl CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.24+ x86-64 Details
pysyntect-0.3.0-cp36-cp36m-macosx_10_7_x86_64.whl CPython 3.6 CPython 3.6 pymalloc macOS 10.7+ x86-64 Details

Total release size:33.4 MB

Release files / pysyntect-0.3.0.tar.gz

Download URL pysyntect-0.3.0.tar.gz
Size 3.3 MB
Tags Source
SHA-256 checksum
How to use checksums
ffcb227dc57bffe6e194842944f8d16e49d77d6affd08c8c213d0e2d4e956c43
BLAKE2b-256 checksum
How to use checksums
294b2459fcaca396848385c620529c6f24711ff522a05db2c9309b1d9ae47a66
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/0.10.4

Release files / pysyntect-0.3.0-cp39-none-win_amd64.whl

Download URL pysyntect-0.3.0-cp39-none-win_amd64.whl
Size 2.5 MB
Tags CPython 3.9 Windows x86-64
SHA-256 checksum
How to use checksums
61b70ad75477acafe63e567e6162f052b43d73e9a21609592163371d6c59fcf8
BLAKE2b-256 checksum
How to use checksums
d65c1187c8269e8a66f3b9bcdd4f60f40f9a836cd0bd06a7426ef26224b90963
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/0.10.4

Release files / pysyntect-0.3.0-cp39-cp39-manylinux_2_24_x86_64.whl

Download URL pysyntect-0.3.0-cp39-cp39-manylinux_2_24_x86_64.whl
Size 2.5 MB
Tags CPython 3.9 Linux glibc 2.24+ x86-64
SHA-256 checksum
How to use checksums
864307f1da6a45872601ba7389eec48e768cd66268a143ea689a75bf5b262cb9
BLAKE2b-256 checksum
How to use checksums
e1c8cd0bcfc2d806d9e585219fcad692856e98dfdef2ba5ed54af2d8251e0945
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/0.10.4

Release files / pysyntect-0.3.0-cp39-cp39-macosx_10_7_x86_64.whl

Download URL pysyntect-0.3.0-cp39-cp39-macosx_10_7_x86_64.whl
Size 2.5 MB
Tags CPython 3.9 macOS 10.7+ x86-64
SHA-256 checksum
How to use checksums
dd0633f3843bc91106a628d0226a6d737fcdd2f230792d474f9fb0839de7c2be
BLAKE2b-256 checksum
How to use checksums
eedbde95f16f6c7d0458e746da455da5b9fe726dd0a2da03a651564fc0c5d06b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/0.10.4

Release files / pysyntect-0.3.0-cp38-none-win_amd64.whl

Download URL pysyntect-0.3.0-cp38-none-win_amd64.whl
Size 2.5 MB
Tags CPython 3.8 Windows x86-64
SHA-256 checksum
How to use checksums
b7d7e214c599a3a8cc65b24c5d6ee73186cbc5112cd609e4c767cbd450d023a4
BLAKE2b-256 checksum
How to use checksums
bb5b42bb5f4d608f8f0afac46e955213c026133dba005d39e604599bcfccd30e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/0.10.4

Release files / pysyntect-0.3.0-cp38-cp38-manylinux_2_24_x86_64.whl

Download URL pysyntect-0.3.0-cp38-cp38-manylinux_2_24_x86_64.whl
Size 2.5 MB
Tags CPython 3.8 Linux glibc 2.24+ x86-64
SHA-256 checksum
How to use checksums
80973fe0c6bada07405c4d498bcefd5d49a94b3a633fbd698d1d00f1347d684f
BLAKE2b-256 checksum
How to use checksums
8745a262775155bf8f378288c3991ce4a6b73ed8a27c4263691f51897891e2bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/0.10.4

Release files / pysyntect-0.3.0-cp38-cp38-macosx_10_7_x86_64.whl

Download URL pysyntect-0.3.0-cp38-cp38-macosx_10_7_x86_64.whl
Size 2.5 MB
Tags CPython 3.8 macOS 10.7+ x86-64
SHA-256 checksum
How to use checksums
7af9671da2753813ba3665e41a2a83880b74cbfe810780754be388698215c8ea
BLAKE2b-256 checksum
How to use checksums
0cbaf17b6d5675501fd2005c16e2dcf0f99a1519a86210d08a9282821d7bec6a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/0.10.4

Release files / pysyntect-0.3.0-cp37-none-win_amd64.whl

Download URL pysyntect-0.3.0-cp37-none-win_amd64.whl
Size 2.5 MB
Tags CPython 3.7 Windows x86-64
SHA-256 checksum
How to use checksums
65d930b9ccce5a8058158436e16442dfd363fa64a855d5ed560facb9e060d4e1
BLAKE2b-256 checksum
How to use checksums
b0262a8bffa71d260ec9038d1d2f6b73d5d550e510bc3f60babf3cb529caa7a9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/0.10.4

Release files / pysyntect-0.3.0-cp37-cp37m-manylinux_2_24_x86_64.whl

Download URL pysyntect-0.3.0-cp37-cp37m-manylinux_2_24_x86_64.whl
Size 2.5 MB
Tags CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.24+ x86-64
SHA-256 checksum
How to use checksums
21303f8544c380fbb4cf64497d4898a164915cdebc733ce42072ee512cd66c39
BLAKE2b-256 checksum
How to use checksums
b8d2fd9db2d780c65ff4149743844e80234e1f1164db5e890ca0b20236d38538
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/0.10.4

Release files / pysyntect-0.3.0-cp37-cp37m-macosx_10_7_x86_64.whl

Download URL pysyntect-0.3.0-cp37-cp37m-macosx_10_7_x86_64.whl
Size 2.5 MB
Tags CPython 3.7 CPython 3.7 pymalloc macOS 10.7+ x86-64
SHA-256 checksum
How to use checksums
458c9e748151b66178e2ed617c2466d08f7c52c1938641dc5695dbb6f5a5a31c
BLAKE2b-256 checksum
How to use checksums
96892dbea8c202252ab12bbf97aa911952e6231a5bd4356e5e1ea0918d413f16
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/0.10.4

Release files / pysyntect-0.3.0-cp36-none-win_amd64.whl

Download URL pysyntect-0.3.0-cp36-none-win_amd64.whl
Size 2.5 MB
Tags CPython 3.6 Windows x86-64
SHA-256 checksum
How to use checksums
f910f40c84e7fc83e8ff2befe34c2bab68f68e5b9decc0d9bf8a80dc355d5661
BLAKE2b-256 checksum
How to use checksums
a5d589c6d5c1bedef1ce3a0c31f3f4fee3da7d2465b902c22ae263e63b40287a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/0.10.4

Release files / pysyntect-0.3.0-cp36-cp36m-manylinux_2_24_x86_64.whl

Download URL pysyntect-0.3.0-cp36-cp36m-manylinux_2_24_x86_64.whl
Size 2.5 MB
Tags CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.24+ x86-64
SHA-256 checksum
How to use checksums
6619c93fe3c46f9a22c25098fdf6b72d2735b5b9a4bada00c4ae4a4f9fe6de0a
BLAKE2b-256 checksum
How to use checksums
1cfdbfba4f8330f08f883ec05da2c75d18c0868a2157c973acf996e196e615d1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/0.10.4

Release files / pysyntect-0.3.0-cp36-cp36m-macosx_10_7_x86_64.whl

Download URL pysyntect-0.3.0-cp36-cp36m-macosx_10_7_x86_64.whl
Size 2.5 MB
Tags CPython 3.6 CPython 3.6 pymalloc macOS 10.7+ x86-64
SHA-256 checksum
How to use checksums
837777bb3356f1838ae6aed4f31bf4a499d90736f0a115e82593e0d690328f27
BLAKE2b-256 checksum
How to use checksums
a8be3d03e869010fbde1a91d6242d5d240ef5debdb7e7877645cbfff60494918
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/0.10.4

Release history Release notifications | RSS feed

This release

0.3.0 This release

13 release files

0.1.2

13 release files

0.1.1

13 release files

0.1.0

12 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