{"id":28094,"library":"pyoxipng","title":"pyoxipng","description":"Python wrapper for oxipng, a multithreaded PNG optimizer. Version 9.1.1 supports Python >=3.8 and is actively maintained. Releases follow oxipng upstream closely, typically every few months.","status":"active","version":"9.1.1","language":"python","source_language":"en","source_url":"https://github.com/opensourcepack/pyoxipng","tags":["png","optimization","image","multithreaded"],"install":[{"cmd":"pip install pyoxipng","lang":"bash","label":"Install from PyPI"}],"dependencies":[{"reason":"For loading/saving images when using the Pillow integration","package":"pillow","optional":true}],"imports":[{"note":"oxipng is the Rust crate; the Python package is pyoxipng.","wrong":"import oxipng","symbol":"optimize_png","correct":"from pyoxipng import optimize_png"}],"quickstart":{"code":"from pyoxipng import optimize_png\n\nwith open('input.png', 'rb') as f:\n    data = f.read()\nresult = optimize_png(data)\nwith open('output.png', 'wb') as f:\n    f.write(result)","lang":"python","description":"Read a PNG from file, optimize it in memory, and save the result."},"warnings":[{"fix":"Open the file in binary read mode and pass bytes.","message":"optimize_png accepts bytes, not a file path. Passing a file path will fail silently or raise TypeError.","severity":"gotcha","affected_versions":"all"},{"fix":"Update code from `result, changed = optimize_png(data)` to `result = optimize_png(data)`. Use `if result != data:` to check if optimized.","message":"Version 7.0.0 changed the return type from (bytes, bool) to bytes. The second element (whether the image was changed) was removed.","severity":"breaking","affected_versions":">=7.0.0, <8.0.0"},{"fix":"Replace `optimize_png(data, level=6)` with `optimize_png(data, opts=dict(level=6))`.","message":"The `level` parameter in optimize_png is deprecated since 8.0.0, use `opts` dict instead.","severity":"deprecated","affected_versions":">=8.0.0"}],"env_vars":null,"last_verified":"2026-05-09T00:00:00.000Z","next_check":"2026-08-07T00:00:00.000Z","problems":[{"fix":"Open the file in binary mode: `with open('file.png', 'rb') as f: data = f.read()`.","cause":"Passing a file path string instead of bytes to optimize_png.","error":"TypeError: expected bytes, got str"},{"fix":"Upgrade to 9.1.1: `pip install --upgrade pyoxipng` and use `from pyoxipng import optimize_png`.","cause":"Old version (pre-7.0) had different API or the module is not installed correctly.","error":"AttributeError: module 'pyoxipng' has no attribute 'optimize_png'"},{"fix":"Add `from pyoxipng import optimize_png` at the top of the script.","cause":"Forgot to import the function correctly.","error":"NameError: name 'optimize_png' is not defined"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}