{"id":20165317,"url":"https://github.com/w-henderson/huffpy","last_synced_at":"2025-03-03T03:23:23.797Z","repository":{"id":129970099,"uuid":"317576440","full_name":"w-henderson/Huffpy","owner":"w-henderson","description":"🗜️ Lightweight and efficient Python library for Huffman coding.","archived":false,"fork":false,"pushed_at":"2020-12-01T15:15:50.000Z","size":602,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-13T14:52:19.493Z","etag":null,"topics":["compression","huffman-coding","huffman-compression-algorithm","huffman-tree","lossless-compression-algorithm","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/w-henderson.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-12-01T14:59:59.000Z","updated_at":"2023-10-23T14:32:43.000Z","dependencies_parsed_at":null,"dependency_job_id":"786b8ad7-10b1-49c9-a4e8-5e16e66aa14c","html_url":"https://github.com/w-henderson/Huffpy","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/w-henderson%2FHuffpy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/w-henderson%2FHuffpy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/w-henderson%2FHuffpy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/w-henderson%2FHuffpy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/w-henderson","download_url":"https://codeload.github.com/w-henderson/Huffpy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241601318,"owners_count":19988899,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["compression","huffman-coding","huffman-compression-algorithm","huffman-tree","lossless-compression-algorithm","python"],"created_at":"2024-11-14T00:37:27.985Z","updated_at":"2025-03-03T03:23:23.792Z","avatar_url":"https://github.com/w-henderson.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Huffpy Banner](assets/banner.png)\n![GitHub Workflow Status](https://img.shields.io/github/workflow/status/w-henderson/Huffpy/HuffpyTest) ![GitHub](https://img.shields.io/github/license/w-henderson/Huffpy) ![Python Version 3](https://img.shields.io/badge/python-3-blue)\n\n# Huffpy\nHuffpy is a simple and efficient Huffman coding library for Python. It was written for a school project but I've since developed it further into a proper robust Python library.\n\n## What is Huffman coding?\nHuffman coding is a lossless compression algorithm used for text which works by performing a frequency analysis and assigning bit patterns to each character based on how frequently it appears. You can find a better description on [the Huffman coding Wikipedia page](https://en.wikipedia.org/wiki/Huffman_coding).\n\n## How do I install it?\nSimply clone the repo and run `python setup.py install` to install the package. It has no dependencies, so there's no need to install any!\n\n## Example Programs\nHere's a very simple program to demonstrate how easy it is to use Huffman coding with Huffpy.\n\n```py\nimport huffpy\n\ncoder = huffpy.HuffmanCoder()\nstringToEncode = \"Hello from Huffpy!\"\n\nhuffmanString, tree = coder.encode(stringToEncode)\nhuffmanBytes = coder.toBytes(huffmanString, tree)\n\ndecodedHuffmanString, decodedTree = coder.fromBytes(huffmanBytes)\ndecodedString = coder.decode(decodedHuffmanString, decodedTree)\n\nassert stringToEncode == decodedString\n```\n\nThere's also a shortcuts module for common combinations of commands, so the above program could be written as follows:\n\n```py\nimport huffpy.shortcuts\n\nstringToEncode = \"Hello from Huffpy!\"\n\nhuffmanBytes = huffpy.shortcuts.stringToHuffmanBytes(stringToEncode)\ndecodedString = huffpy.shortcuts.huffmanBytesToString(huffmanBytes)\n\nassert stringToEncode == decodedString\n```\n\n# Documentation\n\n## [huffman.py](huffpy/huffman.py)\n### HuffmanCoder class\n- `encode(string, showOutput=False)`: encodes a regular string using Huffman coding, returning both the Huffman-coded string and its tree, in that order. If `showOutput` is true, show the percentage completed every 20000 characters.\n- `decode(string, tree)`: decodes a Huffman-coded string and its tree, returning the original uncompressed string.\n- `toBytes(string, tree)`: converts the Huffman-coded string and its tree into bytes, ready to be written to a file.\n- `fromBytes(_bytes)`: converts the bytes from `toBytes` back into a string and a tree, ready to be decoded.\n\n## [shortcuts.py](huffpy/shortcuts.py)\n- `stringToHuffmanBytes(string)`: converts a regular string into Huffman-coded bytes, the equivalent of running `encode` followed by `toBytes`.\n- `huffmanBytesToString(_bytes)`: converts the Huffman-coded bytes back into a regular string, the equivalent of running `fromBytes` followed by `decode`.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fw-henderson%2Fhuffpy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fw-henderson%2Fhuffpy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fw-henderson%2Fhuffpy/lists"}