Skip to main content

Render reproducible examples of Python code for sharing.

Project description

reprexlite: Python reproducible examples for sharing

PyPI Supported Python versions tests codecov

reprexlite is tool for rendering reproducible examples of Python code for sharing. It will execute your code and embed the outputs as comments below their associated lines. The rendered reprex can then be easily copied, pasted, and run as-is by anybody else. It is a lightweight alternative to reprexpy and is similarly meant as a port of the R package reprex.

Here's an example of output created by reprexlite:

arr = [1, 2, 3, 4, 5]
[x + 1 for x in arr]
#> [2, 3, 4, 5, 6]

Why reproducible examples?

If you're asking for help or reporting a bug, you are more likely to succeed in getting others to help you if you include a good reprex. If you're writing documentation, your readers will appreciate examples that they can easily run.

Why reprexlite?

reprexlite helps you create a self-contained reprex that can be easily copy-pasted and run. Your code runs in an isolated namespace. The reprex is formatted so that it is valid Python code with outputs as comments, unlike copying from a REPL. reprexlite is also very lightweight and has a convenient CLI, so you can easily and quickly get it up and running in a virtual environment.

Installation

reprexlite is available on PyPI:

pip install reprexlite

Optional dependencies can be specified using the "extras" mechanism, e.g., reprexlite[pygments]. Available extras are:

  • black : for optionally autoformatting your code
  • pygments : for syntax highlighting and the RTF venue

Development version

The development version of reprexlite is available on GitHub:

pip install https://github.com/jayqi/reprexlite.git#egg=reprexlite

Quick usage

Command-line interface

The reprexlite CLI allows you to create a reprex without entering Python. Simply invoke the command

reprex

This will take you into your system's default command-line text editor where you can type or paste your Python code. On macOS, for example, this will be vi. You can set your default editor using the $EDITOR environment variable—I'm personally a fan of nano.

Once you're done, reprexlite will print out your reprex to console.

Python library

The same functionality as the CLI is also available from the reprex function with an equivalent API:

from reprexlite import reprex

code = """
arr = [1, 2, 3, 4, 5]
[x + 1 for x in arr]
"""

reprex(code)
#> <reprexlite.reprex.GitHubReprex object at 0x7fd4446f94f0>

Under the hood, reprexlite is designed with a modular object-oriented architecture. See the API documentation to learn more.

Comparison to reprexpy

Compared to reprexpy, reprexlite adds:

  • A command-line interface so you can create reprexes without entering Python
  • Lighter dependencies (e.g., no dependence on IPython)

However, reprexlite does not have:

  • Direct ability to read from or write to your OS clipboard.
    • Instead, the CLI opens your default text editor which you can paste into.
  • Automatic upload of matplotlib plots to imgur.com.

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

reprexlite-0.2.0.tar.gz (15.9 kB view details)

Uploaded Source

Built Distribution

reprexlite-0.2.0-py3-none-any.whl (16.7 kB view details)

Uploaded Python 3

File details

Details for the file reprexlite-0.2.0.tar.gz.

File metadata

  • Download URL: reprexlite-0.2.0.tar.gz
  • Upload date:
  • Size: 15.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.8.8

File hashes

Hashes for reprexlite-0.2.0.tar.gz
Algorithm Hash digest
SHA256 e111fa2062469b935821b0cd2aae31a415b2b349c0d224c09a632b332042f6f8
MD5 3e5a7b5ab8f7164507b6ffd040e0d3da
BLAKE2b-256 fa47dc033eee907242d1f6bda13e6e3fca5fe88dfdb8a2e9a0bb8491dda9c4f4

See more details on using hashes here.

File details

Details for the file reprexlite-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: reprexlite-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 16.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.8.8

File hashes

Hashes for reprexlite-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 19891b62357892327b05fdfd3938b4b33cc792fbfef80d1c63a00083aa76b107
MD5 580afdd3071fa77d9456acc0b6681e09
BLAKE2b-256 3cfe1d1b691f905c1e2803258ab62103a6e7d77f8e5e5df0a3dd9cbad317ce41

See more details on using hashes here.

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