Skip to main content
ⓘ

Downloads Downloads Coverage Status Lines of code Hits-of-Code Test-Package Python versions PyPI version Checked with mypy Ruff DeepWiki

logo

It's a micro-library for customizing sys.displayhook.

If you need to change the default behavior of sys.displayhook, this library lets you do it:

  • 💎 declaratively
  • 🫥 compactly
  • 🌞 beautifully

Table of contents

Quick start

Install it:

pip install displayhooks

Then use:

import sys
from displayhooks import not_display

not_display(int)

sys.displayhook('Most of the adventures recorded in this book really occurred; one or two were experiences of my own, the rest those of boys who were schoolmates of mine.')
#> 'Most of the adventures recorded in this book really occurred; one or two were experiences of my own, the rest those of boys who were schoolmates of mine.'
sys.displayhook(666)
# [nothing!]

Transform displayed values

You can declaratively define a converter function for displayed values. Its return value will be passed to the original displayhook function.

import sys
from displayhooks import converted_displayhook

@converted_displayhook
def new_displayhook(value):
    return value.lower()

sys.displayhook("What’s gone with that boy, I wonder? You TOM!")
#> 'what’s gone with that boy, i wonder? you tom!'

If your function returns None, nothing is displayed.

Prohibiting the display of certain types of values

You can disable the display of certain data types, similar to how NoneType values are ignored by default.

You could already see a similar example above, let's look at it again:

import sys
from types import FunctionType
from displayhooks import not_display

not_display(FunctionType)

sys.displayhook('Nothing! Look at your hands. And look at your mouth. What is that truck?')
#> 'Nothing! Look at your hands. And look at your mouth. What is that truck?'
sys.displayhook(lambda x: x)
# [nothing!]

In this example, you can see that we have disabled the display for functions, but all other data types are displayed unchanged.

Automatic recovery of the default hook

You can limit the impact on sys.displayhook only to the code inside a function. If you hang the autorestore_displayhook decorator on it, after exiting the function, the displayhook that was installed before it was called will be automatically restored:

import sys
from types import FunctionType
from displayhooks import not_display, autorestore_displayhook

@autorestore_displayhook
def do_something_dangerous():
    not_display(FunctionType)
    sys.displayhook(do_something_dangerous)
    # [nothing!]

do_something_dangerous()

sys.displayhook(do_something_dangerous)
#> <function do_something_dangerous at 0x104c980e0>

Metadata

Release files for displayhooks 0.0.7

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

Source distribution (sdist)

Source distribution for displayhooks 0.0.7
File Size Uploaded
displayhooks-0.0.7.tar.gz 5.9 kB Details

Built distribution (wheel)

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

Total release size: 11.4 kB

Release files / displayhooks-0.0.7.tar.gz

Download URL displayhooks-0.0.7.tar.gz
Size 5.9 kB
Tags Source
SHA-256 checksum
How to use checksums
aa02d6df869cc48acb6f0c373fed298ad0a59ca8d14bc0bd3679993b2a3131ff
BLAKE2b-256 checksum
How to use checksums
9f1449b1d8d10da5b0b3b6673d184e440d1dc284d3a55c8efeba2cead7626f98
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jun 30, 2026.

Transparency log

Release files / displayhooks-0.0.7-py3-none-any.whl

Download URL displayhooks-0.0.7-py3-none-any.whl
Size 5.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f45c63a61b6a8fa10f042cf6ed42ba80ccab4914414519b82c8b0fede74c0830
BLAKE2b-256 checksum
How to use checksums
d5c7abed000e852c9076a31c1826595425c90d04c0042d4c099169f319f463ec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jun 30, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.0.7 This release

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 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