Skip to main content

Python interface to generate Typst code.

Project description

python-typst

python-typst is a library for generating executable typst code (See typst repository and typst documentation for more information). It is written primarily in functional programming paradigm with some OOP content.

This package provides the interfaces in a way that is as close as possible to typst's native functions. Through python-typst and other data processing packages, you can generate data reports quickly.

Repository on GitHub: python-typst. Homepage on PyPI: python-typst. Contributions are welcome.

Installation

pip install typstpy

Examples

text

>>> text("Hello, World!", font="Arial", fallback=True)
'#text(font: "Arial", fallback: true)[Hello, World!]'
>>> text("Hello, World!", font=("Arial", "Times New Roman"), fallback=True)
'#text(font: ("Arial", "Times New Roman"), fallback: true)[Hello, World!]'
>>> text("Hello, World!", size=Length(12, "pt"))
'#text(size: 12pt)[Hello, World!]'
>>> text("Hello, World!", fill=color("red"))
'#text(fill: rgb("#ff4136"))[Hello, World!]'

emph

>>> emph("Hello, World!")
'#emph[Hello, World!]'

strong

>>> strong("Hello, World!")
'#strong[Hello, World!]'
>>> strong("Hello, World!", delta=300)
'#strong(delta: 300)[Hello, World!]'

par

>>> par("Hello, World!", leading=Length(1.5, "em"))
'#par(leading: 1.5em)[Hello, World!]'
>>> par("Hello, World!", justify=True)
'#par(justify: true)[Hello, World!]'
>>> par("Hello, World!")
'Hello, World!'

heading

>>> heading("Hello, World!", level=2, supplement=Content("Chapter"), label=Label("chap:chapter"))
'#heading(supplement: [Chapter], level: 2)[Hello, World!] <chap:chapter>'
>>> heading("Hello, World!", level=2)
'== Hello, World!'

image

>>> image("image.png")
'#image("image.png")'
>>> image("image.png", format="png")
'#image("image.png", format: "png")'

figure

>>> figure(image("image.png"))
'#figure(image("image.png"))'
>>> figure(image("image.png"), caption=Content("This is a figure."))
'#figure(image("image.png"), caption: [This is a figure.])'
>>> figure(image("image.png"), caption=Content("This is a figure."), label=Label("fig:figure"))
'#figure(image("image.png"), caption: [This is a figure.]) <fig:figure>'
>>> figure(image("image.png"), caption=figure.caption("This is a figure.", separator=Content("---")))
'#figure(image("image.png"), caption: figure.caption(separator: [---])[This is a figure.])'

Current Support

Name Parameters Implement Type
cmyk cyan, magenta, yellow, key STANDARD
color name NOTSTANDARD
rgb args STANDARD
color.hsl hue, saturation, lightness, alpha STANDARD
color.linear_rgb red, green, blue, alpha STANDARD
emph content STANDARD
figure content, caption, label STANDARD
figure.caption content, position, separator STANDARD
heading content, level, supplement, numbering, label STANDARD
image path, format, width, height, alt, fit STANDARD
luma lightness, alpha STANDARD
par content, leading, justify, linebreaks, first_line_indent, hanging_indent STANDARD
rgb args STANDARD
strong content, delta STANDARD
text content, font, fallback, size, fill STANDARD

STANDARD means you could find implementation in typst. NOTSTANDARD means this function is not the standard implementation of corresponding function in typst, or is not implemented in typst but for convenience.

Project details


Download files

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

Source Distribution

typstpy-0.0.4.tar.gz (11.6 kB view hashes)

Uploaded Source

Built Distribution

typstpy-0.0.4-py3-none-any.whl (13.3 kB view hashes)

Uploaded Python 3

Supported by

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