Skip to main content

This repository contains a Python encoder and decoder for the GIF file format.

The easiest way to get PyGIF is to install from the Python Packaging Index:

pip install pygif

The following will generate an 8x8 checkerboard image:

import gif

writer = gif.Writer (open ('checkerboard.gif', 'wb'))
writer.write_header ()
writer.write_screen_descriptor (8, 8, has_color_table = True, depth = 1)
writer.write_color_table ([(0, 0, 0), (255, 255, 255)], 1)
writer.write_image (8, 8, 1, [ 1, 0, 1, 0, 1, 0, 1, 0,
                               0, 1, 0, 1, 0, 1, 0, 1,
                               1, 0, 1, 0, 1, 0, 1, 0,
                               0, 1, 0, 1, 0, 1, 0, 1,
                               1, 0, 1, 0, 1, 0, 1, 0,
                               0, 1, 0, 1, 0, 1, 0, 1,
                               1, 0, 1, 0, 1, 0, 1, 0,
                               0, 1, 0, 1, 0, 1, 0, 1 ])
writer.write_trailer ()

The following will decode that image:

import gif

file = open ('checkerboard.gif', 'rb')
reader = gif.Reader ()
reader.feed (file.read ())
if reader.has_screen_descriptor ():
    print ('Size: %dx%d' % (reader.width, reader.height))
    print ('Colors: %s' % repr (reader.color_table))
    for block in reader.blocks:
        if isinstance (block, gif.Image):
            print ('Pixels: %s' % repr (block.get_pixels ()))
    if reader.has_unknown_block ():
        print ('Encountered unknown block')
    elif not reader.is_complete ():
        print ('Missing trailer')
else:
    print ('Not a valid GIF file')

Giving the following output:

Size: 8x8
Colors: [(0, 0, 0), (255, 255, 255)]
Pixels: [1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1]

Metadata

Release files for pygif 0.5

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

Source distribution (sdist)

Source distribution for pygif 0.5
File Size Uploaded Provenance Actions
pygif-0.5.tar.gz 114.0 kB With provenance Details for pygif-0.5.tar.gz

Built distribution (wheel)

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

Total release size: 128.7 kB

Release files / pygif-0.5.tar.gz

Download URL pygif-0.5.tar.gz
Size 114.0 kB
Tags Source
SHA-256 checksum
How to use checksums
3c700240bf97f1872843306e8f1734d40c15d07543decc0d646e5f9ebeddcbb4
BLAKE2b-256 checksum
How to use checksums
0ce7e9a055424a27301504d291c71af093b01b55aa02206fa2392b9dc3d874c0
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 25, 2026.

Transparency log

Release files / pygif-0.5-py3-none-any.whl

Download URL pygif-0.5-py3-none-any.whl
Size 14.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c45d0719da98c2e8f5306415c434ee2f58bf28001ab95d81f70918b455129a7d
BLAKE2b-256 checksum
How to use checksums
6a90bcdff2edebbeed24cf48a44e0e897b5963f399068421b30a86393120bafb
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 25, 2026.

Transparency log

Security for pygif 0.5

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pygif-0.5.tar.gz

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 25, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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