Skip to main content

DisplayLang

The problem: Support a limited subset of the Python language, powerful enough to allow authors to conveniently build HTML displays based on SymPy classes, but limited enough to offer a reasonable expectation of safe evaluation.

We call the language "DisplayLang". It was originally designed for authoring example explorers in Proofscape, but it attempts to solve a fairly general problem, so should be more broadly useful.

In fact the set of AllowedCallables for SymPy functions and classes which can be used in Proofscape is defined in the pfsc-examp project, not here. This project is more foundational, defining AST node traversers, providing the basic framework for defining AllowedCallables, and defining these for built-in Python functions and methods.

The language

The syntax is defined by three things:

  • Which statement and expression types in the Python language we support.
  • Which callables we allow to be called.
  • For the allowed callables, what types the arguments are allowed to be, and, when they are strings, what regexes the strings must match.

The reason for paying special attention to string arguments is that there are functions that are definitely unsafe if they can be passed arbitrary strings, but are probably safe as long as either we don't allow strings to be passed at all, or we allow only strings of certain restricted forms.

Of course we need to be careful about built-in Python callables, such as exec and eval, not to mention things like os.system. So our overall solution is to ban all function calls outside a finite, curated, set of approved calls. The set is expected to grow over time, in response to user demand.

Among banned statement types are import statements, which supports the providing of only a finite, curated set of available names.

Getting started

Better docs are on the way, but for now we offer the following hints for getting started:

  • See the displaylang.build.DisplayLangProcessor.process() method, for the core code that processes a string of DisplayLang.

    • See also the displaylang.build.make_displaylang_processor() convenience function for building a DisplayLangProcessor instance.
  • Check out the displaylang.allow.AllowedCallable.__init__() method to see how an AllowedCallable is defined.

Metadata

Release files for displaylang 0.24.1

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

Source distribution (sdist)

Source distribution for displaylang 0.24.1
File Size Uploaded Provenance Actions
displaylang-0.24.1.tar.gz 32.9 kB Without provenance Details for displaylang-0.24.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for displaylang 0.24.1
File Interpreter ABI Platform Actions
displaylang-0.24.1-py3-none-any.whl Python 3 none any Details for displaylang-0.24.1-py3-none-any.whl

Total release size: 65.8 kB

Release files / displaylang-0.24.1.tar.gz

Download URL displaylang-0.24.1.tar.gz
Size 32.9 kB
Tags Source
SHA-256 checksum
How to use checksums
e2876d95819c6b55fa1cd4b0cb128e0eedd9aafd75a5eec159228f43eb398894
BLAKE2b-256 checksum
How to use checksums
f05588118b0cd38bc8ffbe7581e143b4156379f7b9daad0e7f29f226f3999a38
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.8.16

Release files / displaylang-0.24.1-py3-none-any.whl

Download URL displaylang-0.24.1-py3-none-any.whl
Size 33.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5c64a3272d9476aa7259f36b1505ac8ffb90667dacf46bdd119ec5433805ef75
BLAKE2b-256 checksum
How to use checksums
1295aa6a53248cf8814ec28c875b6495d5961720b969901f8f86571471a6af3a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.8.16

Security for displaylang 0.24.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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