papertrail
API Reference
Motivation
- Documentation can get out of date quickly
- Sometimes its harder to explain what a function does in plain english than it is to just show what the input and outputs would be:
- e.g:
- "Multiply the value strings by the amount that is the key".
- vs
f({"a": 1, "b": 2, "c": 4}) == ['a', 'bb', 'cccc']
- e.g:
- Tests are the best form of documentation because they complain when they go out of sync
- Doctests are an interesting way of writing tests however they can be fiddly and harder to set up than proper testing frameworks
- Resorting to only using doctests means missing out on features like fixtures and parameterisation
- Having some tests that are written in tests and some that are in doctests means keeping track of two places as the "source of truth"
Installation
uv add papertrail
Example
Use the example function to capture an example from a test to add to the docstring.
Wrap the example around the function before the equality operation and the function result will be captured and added to the docstring of the function. This only happens if the tests pass!
from papertrail import example
def test_add():
assert example(add, 2, 3) == 5
This has captured the example and now once the tests are finished the docstring of the function will be updated like this:
def add(a: int, b: int) -> int:
"""Papertrail examples:
>>> add(2, 3) == 5
True
::
"""
return a + b
You can use it with parametrized tests too:
@pytest.mark.parametrize(
("args", "kwargs", "expected_result"),
[
pytest.param((2, 2), {}, 0),
pytest.param((2,), {"b": 3}, -1),
],
)
def test_func_b(args, kwargs, expected_result):
assert example(func_b, *args, **kwargs) == expected_result
This captures all the cases and adds them to the functions docstring:
def func_b(a: float, b: float) -> float:
"""Simple docstring
Args:
a (float)
b (float)
Returns:
float
Papertrail examples:
>>> func_b(2, 2) == 0
True
>>> func_b(2, b=3) == -1
True
::
"""
return a - b
Repo map
├── .github
│ └── workflows
│ ├── ci_tests.yaml
│ └── publish.yaml
├── src
│ └── papertrail
│ ├── adapters
│ │ ├── __init__.py
│ │ └── io_funcs.py # The IO functions for the IO adapters
│ ├── core
│ │ ├── collection
│ │ │ ├── __init__.py
│ │ │ ├── example.py # User entrypoint `example` and it's inner class `Example`
│ │ │ ├── record.py
│ │ │ └── recorder.py
│ │ ├── transformation
│ │ │ ├── __init__.py
│ │ │ ├── ast_editing.py
│ │ │ ├── format_examples.py
│ │ │ └── transform.py # Updates the the docstrings for all the funcs in the files in the example cache.
│ │ ├── __init__.py
│ │ └── logger.py
│ ├── __init__.py
│ └── __main__.py # the pytest hook for sessionfinish
├── tests
│ ├── _mock_data
│ │ ├── mock_src
│ │ │ ├── __init__.py
│ │ │ ├── mod_a.py
│ │ │ └── mod_b.py
│ │ └── tests
│ │ ├── __init__.py
│ │ ├── conftest.py
│ │ ├── test_mod_a.py
│ │ └── test_mod_b.py
│ ├── core
│ │ ├── collection
│ │ │ ├── __init__.py
│ │ │ ├── test_example.py
│ │ │ ├── test_record.py
│ │ │ └── test_recorder.py
│ │ └── transformation
│ │ ├── __init__.py
│ │ ├── test_ast_editing.py
│ │ └── test_format_examples.py
│ └── test_main.py
├── .pre-commit-config.yaml
├── README.md
├── pyproject.toml
├── ruff.toml
└── uv.lock
(generated with repo-mapper-rs)
::
Release files for papertrail 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| papertrail-0.1.2.tar.gz | 6.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| papertrail-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 18.3 kB
Release files / papertrail-0.1.2.tar.gz
| Download URL | papertrail-0.1.2.tar.gz |
|---|---|
| Size | 6.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f4497fd35f8fb102612112dc8231f0bab9a6d8244ac2ab14650e905dabed2ddd
|
|
BLAKE2b-256 checksum How to use checksums |
46455299ca269c96ae46c58a4e51f1d4a44941eabd5fbede9d56c06637fb312f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 12, 2026.
Transparency logRelease files / papertrail-0.1.2-py3-none-any.whl
| Download URL | papertrail-0.1.2-py3-none-any.whl |
|---|---|
| Size | 11.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d45260e555c641525248d6ed7e84a6d37a58b61e1e29bda6d538729ca9f0cbd3
|
|
BLAKE2b-256 checksum How to use checksums |
41c5fc531f78c9bc5e8cc29fe62ad1b6a7f454a2e32ecf6842b4cb6fea0fcaad
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 12, 2026.
Transparency log