Python 3.13 removes imghdr which I need. Solution(s)?

I need imghdr for a program. I have seen possible alternatives, namely, (1) filetype · PyPI (2) puremagic · PyPI and (3) python-magic · PyPI

Not sure if any of these will work and I thought I should ask before I take some step that might bork my system.

I haven’t used any of them, but judging by the descriptions they should probably all work (but I only had a quick skim). :man_shrugging:

python-filetype and python-puremagic are in the extra repo. I’d try them if it was me.

You could install them in a venv using pip.

You could write your own.

Python312 is still available in the AUR, but you’ll need to adapt at some point.

I doubt any of them would bork your system. :smiley:

What program? Whatever it is, the developer needs to adapt to upstream changes.

Reference:

1 Like

Thanks, I tried python-filetype but that did not solve the problem. I ended up installing python-deadlib which includes python-imghdr and that solved the problem. :grinning:

1 Like

Some additional info that may or may not be of interest.

Instead of using old code with no maintainers, I think it’s better to use PIL (the fork Pillow):

>>> import os
>>> from PIL import Image
>>> i = Image.open(os.path.expanduser("~/my-unknown-image"))
>>> i.info
{'jfif': 257, 'jfif_version': (1, 1), 'jfif_unit': 0, 'jfif_density': (1, 1)}

You can also (at least quite often) read off a few bytes in binary mode and get the info from there. It all depends on what you are looking for. Suffice it to say, that PIL can read LOTS of formats (https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html), though I think it currently doesn’t have support for avif, but it may have changed recently, but if it hasn’t an additional module needs to be installed, such as pillow_avif, which I use.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.