{ "info": { "author": "Stefaan Lippens", "author_email": "soxofaan@gmail.com", "bugtrack_url": null, "classifiers": [ "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.6", "Topic :: System :: Archiving :: Compression" ], "description": "dahuffman - Python Module for Huffman Encoding and Decoding\n===========================================================\n\n\n.. image:: https://img.shields.io/travis/soxofaan/dahuffman/master.svg\n :target: https://travis-ci.org/soxofaan/dahuffman\n\n.. image:: https://img.shields.io/badge/license-MIT-blue.svg\n :target: https://raw.githubusercontent.com/soxofaan/dahuffman/master/LICENSE.txt\n\n\n-------------------------\n\ndahuffman is a pure Python module for Huffman encoding and decoding,\ncommonly used for lossless data compression.\n\nThe name of the module refers to the full name of the inventor\nof the Huffman code tree algorithm: David Albert Huffman (August 9, 1925 \u2013 October 7, 1999).\n\nFeatures and design\n-------------------\n\n- Pure Python implementation, only using standard library.\n- Leverages iterators and generators internally, allows to be used in streaming fashion.\n- Not limited to byte/unicode string input, can handle other \"symbols\" or tokens,\n for example chess moves or sequences of categorical data, as long as these symbols\n can be used as keys in dictionaries (meaning they should be hashable).\n- properly handle end of encoded bit stream if it does not align with byte boundaries\n- supports both Python 2.7 and Python 3.6\n\nInstallation\n------------\n\nTODO\n\n\nUsage\n-----\n\nBasic usage example, where the code table is built based on given symbol frequencies::\n\n >>> from dahuffman import HuffmanCodec\n >>> codec = HuffmanCodec.from_frequencies({'e': 100, 'n':20, 'x':1, 'i': 40, 'q':3})\n >>> encoded = codec.encode('exeneeeexniqneieini')\n >>> encoded\n '\\x86|%\\x13i@'\n >>> len(encoded)\n 6\n >>> codec.decode(encoded)\n 'exeneeeexniqneieini'\n >>> codec.print_code_table()\n bits code (value) symbol\n 5 00000 ( 0) _EOF\n 1 1 ( 1) 'e'\n 2 01 ( 1) 'i'\n 3 001 ( 1) 'n'\n 4 0001 ( 1) 'q'\n 5 00001 ( 1) 'x'\n\n\nYou can also \"train\" the codec by providing it data directly::\n\n >>> codec = HuffmanCodec.from_data('hello world how are you doing today foo bar lorem ipsum')\n >>> codec.encode('do lo er ad od')\n '^O\\x1a\\xc4S\\xab\\x80'\n >>> len(_)\n 7\n\n\nUsing it with sequences of symbols (country codes in this example)::\n\n >>> countries = ['FR', 'UK', 'BE', 'IT', 'FR', 'IT', 'GR', 'FR', 'NL', 'BE', 'DE']\n >>> codec = HuffmanCodec.from_data(countries)\n >>> encoded = codec.encode(['FR', 'IT', 'BE', 'FR', 'UK'])\n >>> encoded\n 'L\\xca'\n >>> len(encoded)\n 2\n >>> codec.decode(encoded)\n ['FR', 'IT', 'BE', 'FR', 'UK']\n\n\n\nDoing it in a streaming fashion (generators)::\n\n >>> import random\n >>> def sample(n, symbols):\n ... for i in range(n):\n ... if (n-i) % 5 == 1:\n ... print(i)\n ... yield random.choice(symbols)\n ...\n >>> codec = HuffmanCodec.from_data(countries)\n >>> encoded = codec.encode_streaming(sample(16, countries))\n >>> encoded\n \n >>> decoded = codec.decode_streaming(encoded)\n >>> decoded\n \n >>> list(decoded)\n 0\n 5\n 10\n 15\n ['DE', 'BE', 'FR', 'GR', 'UK', 'BE', 'UK', 'IT', 'UK', 'FR', 'DE', 'IT', 'NL', 'IT', 'FR', 'UK']\n\n\n\n\n\n", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/soxofaan/dahuffman", "keywords": "huffman compression encoding decoding", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "dahuffman", "package_url": "https://pypi.org/project/dahuffman/", "platform": "", "project_url": "https://pypi.org/project/dahuffman/", "project_urls": { "Homepage": "https://github.com/soxofaan/dahuffman" }, "release_url": "https://pypi.org/project/dahuffman/0.2/", "requires_dist": null, "requires_python": "", "summary": "Pure Python Huffman encoder and decoder module", "version": "0.2" }, "last_serial": 3223541, "releases": { "0.2": [ { "comment_text": "", "digests": { "md5": "72dd3db9a4d95a52b1252510ac5a5397", "sha256": "4a6f426bad4e6c2e909a4a207565a5a2b92814dfe3e6449da7920c0cc2ab6666" }, "downloads": -1, "filename": "dahuffman-0.2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "72dd3db9a4d95a52b1252510ac5a5397", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 7971, "upload_time": "2017-10-03T22:21:28", "url": "https://files.pythonhosted.org/packages/63/b7/0870d958d49717f6d45ff8740327a55e259ba2e7784346524e9daf71a58a/dahuffman-0.2-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "59a1f19b6bcf8aacc5eaf07ffaeba929", "sha256": "a3ec21cf0f3ee89d265d6c9727dc0781b42ec43e4197e06ebe3bd8a748fb2b78" }, "downloads": -1, "filename": "dahuffman-0.2.tar.gz", "has_sig": false, "md5_digest": "59a1f19b6bcf8aacc5eaf07ffaeba929", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5394, "upload_time": "2017-10-03T22:21:31", "url": "https://files.pythonhosted.org/packages/10/70/113aa324270a434f05b72dd750e5026a85efa69714f5fd7d422627c24de4/dahuffman-0.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "72dd3db9a4d95a52b1252510ac5a5397", "sha256": "4a6f426bad4e6c2e909a4a207565a5a2b92814dfe3e6449da7920c0cc2ab6666" }, "downloads": -1, "filename": "dahuffman-0.2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "72dd3db9a4d95a52b1252510ac5a5397", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 7971, "upload_time": "2017-10-03T22:21:28", "url": "https://files.pythonhosted.org/packages/63/b7/0870d958d49717f6d45ff8740327a55e259ba2e7784346524e9daf71a58a/dahuffman-0.2-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "59a1f19b6bcf8aacc5eaf07ffaeba929", "sha256": "a3ec21cf0f3ee89d265d6c9727dc0781b42ec43e4197e06ebe3bd8a748fb2b78" }, "downloads": -1, "filename": "dahuffman-0.2.tar.gz", "has_sig": false, "md5_digest": "59a1f19b6bcf8aacc5eaf07ffaeba929", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5394, "upload_time": "2017-10-03T22:21:31", "url": "https://files.pythonhosted.org/packages/10/70/113aa324270a434f05b72dd750e5026a85efa69714f5fd7d422627c24de4/dahuffman-0.2.tar.gz" } ] }