Skip to main content

Make repr of bytes better in IPython

Project description

mimebytes

  • Make repr of bytes better in ipython
  • Rich outputs in Jupyter using _repr_png_ and _repr_jpeg_
In [1]: from mimebytes import mime

In [2]: with open('image.png', 'rb') as f:
   ...:     content = f.read()

In [3]: mime(content, 'image/png')
Out[3]: PNGBytes<376151> (image/png)

preview

If python-magic is installed, you do not need to specify the mimetype as it will be autodetected.

In [1]: from mimebytes import mime

In [2]: with open('image.png', 'rb') as f:
   ...:     content = f.read()

In [3]: mime(content)
Out[3]: PNGBytes<376151> (image/png)

Why?

Have you ever tried to output a bytes object in ipython and seen a garbled mess like the following? If so, then this is for you.

In [1]: with open('image.png', 'rb') as f:
   ...:     content = f.read()
   ...:

In [2]: content
Out[2]: b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x02\x00\x00\x00\x01\xd1\x08\x06\x00\x00\x00\x1c\xf2\x01\xed\x00\x00 \x00IDATx\x9c\xec\xbdy\x9cfWU\xef\xfd\xddk\xefs\x9e\xb1\xc6\xee\xeaNO\xe9$\x9d9\x84$\x1d\x08\x19\x84@\x80\x10@\x01\x15d\x14D\x05\x15\x05\x05\xe1\xe2\xf0^\xbdr\xf5\xeau\x06\x04E#*<... continues on forever>

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

mimebytes-0.2.0.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

mimebytes-0.2.0-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mimebytes-0.2.0.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for mimebytes-0.2.0.tar.gz
Algorithm Hash digest
SHA256 6bc09f1a14a7474f967b522d11c894cddcccf937d09a410f00690bcb5dd58703
MD5 121addfcbc2e3d7df813bc4b0f52bcff
BLAKE2b-256 fe1e395e2604d1d2fb4f563943da466840b83433fceabec4cac65940907f2714

See more details on using hashes here.

Provenance

File details

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

File metadata

  • Download URL: mimebytes-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for mimebytes-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bb6eff92a6d15453c913452e5f811b65eead15abd4913cc6c0292a27f8dd1bc9
MD5 d7ea3d382eeae41715b4f72b1c7c7cc3
BLAKE2b-256 b5d44251d936c548ad2a7d9f8b202a76d815b2715c2069b846be261205c566e1

See more details on using hashes here.

Provenance

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