{ "info": { "author": "knknkn1162", "author_email": "knknkn1162@gmail.com", "bugtrack_url": null, "classifiers": [ "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6" ], "description": "# Anyloadump\n\n[![Build Status](https://travis-ci.org/knknkn1162/anyloadump.svg?branch=master)](https://travis-ci.org/knknkn1162/anyloadump)\n[![Coverage Status](https://coveralls.io/repos/github/knknkn1162/anyloadump/badge.svg?branch=master)](https://coveralls.io/github/knknkn1162/anyloadump?branch=master)\n[![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENSE)\n\nThe Python library anyloadump helps to load a file or to dump to a file briefly in various file formats (e.g. json, pickle, yaml, toml..) with importing modules dynamically.\n\n## Motivation\n\nIf the multiple types of file are loaded or dumped, boilerplate code will be generated and scattered as follows:\n\n```python\n# import each module.\nimport json, pickle\nwith open(json_file, \"r\") as f:\n json_obj = json.load(f)\n\n## do something useful\n\n# almost the same as above! Some feel this annoying.\nwith open(pickle_file, \"rb\") as f:\n pickle_obj = pickle.load(f)\n```\n\nThis code goes against DRY(Don't repeat yourself) principle. Let's apply DRY in the problem.\n\n ```python\n # import json, pickle,... <= unnecessary expression because of dynamic importing\n # what we want to do\n def generalized_load(file):\n with open(file, get_mode()) as fp:\n obj = get_module().load(fp)\n\n # or dump version\n def generalized_dump(obj, file):\n with open(file, get_mode()) as fp:\n get_module().dump(obj, fp)\n ```\n\nAnyloadump helps to load a file or to dump to a file briefly in various file types, and provides dump/load/dumps/loads method like [uiri/toml](https://github.com/uiri/toml).\n\n## Installation\n\nTo install the latest release on PyPi, simply run:\n\n```python\npip install anyloadump\n```\n\n## Tutorial\n\nHere is quick tutorial and is so easy to use:)\n\n```python\nimport anyloadump as ald\n\njson_file = \"sample.json\"\nobj = ald.load(json_file)\n\n# binary file can be also loaded properly. \npickle_file = \"sample.pickle\"\nobj = ald.load(pickle_file)\n\n# use library from PyPI. `pip install pyyaml` in advance.\nyaml_file = \"sample.yaml\"\nobj = ald.load(yaml_file)\n\n# set encoding option in open method\npickle_file = \"sample.pickle\"\nobj = ald.load(pickle_file, encoding=\"utf-8\")\n\n# set default_flow_style=False, allow_unicode=True in yaml\nyaml_file = \"sample.yaml\"\nobj = ald.load(yaml_file, default_flow_style=False, allow_unicode=True)\n\n# ---\n\nobj = get_obj()\n# Of course, you can use dump method likewise:\njson_file = \"sample.json\"\nald.dump(obj, json_file)\n\n# binary file can be also loaded properly. \npickle_file = \"sample.pickle\"\nald.dump(obj, pickle_file)\n\n# when use loads/dumps, fmt argument is required\nald.dumps(obj, fmt=\"json\")\n```\n\n## Requirements\n\nAnyloadump makes use of the art of duck typing to modules, and the imported module meets a few requirements and options:\n\n1. `load(fp, **kwargs)` # fp : file object.\n2. `dump(obj, fp, **kwargs)` # obj : Python object, fp : file object\n3. (Optional) `loads(s, **kwargs)` # serialized bytes or strs\n4. (Optional) `dumps(obj, **kwargs)` # obj : Python object\n\nNote)\n1. argument names (obj, fp) are arbitrary.\n2. kwargs are the keyword arguments that are optional arguments of load/dump/loads/dumps method.\n\nCheck it out that `json, pickle, toml` modules have 1\\~4 respectively, by contrast `pyyaml` library only 1\\~2.\nIf you run `anyloadump.loads(\"sample.yaml\")`, CharsetNotInferredError is raised. \n\n\n\n## Note\n\n+ Anyloadump imports module dynamically with `importlib.import_module` method. So if you want to use external library such as [yaml/pyyaml](https://github.com/yaml/pyyaml) or [uiri/toml](https://github.com/uiri/toml), run `pip install` in advance. Or raise ImportError/ModuleNotFoundError(new in Python3.6).\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/knknkn1162/anyloadump", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "anyloadump", "package_url": "https://pypi.org/project/anyloadump/", "platform": "", "project_url": "https://pypi.org/project/anyloadump/", "project_urls": { "Homepage": "https://github.com/knknkn1162/anyloadump" }, "release_url": "https://pypi.org/project/anyloadump/0.1/", "requires_dist": null, "requires_python": "", "summary": "dumper and loader for various file formats.", "version": "0.1" }, "last_serial": 3256392, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "85852e056b76f0459a02a78d302cd7b1", "sha256": "3a4b727e875309bd38b20bc6f358aefb49f535ee335366331330e2f4085b0a00" }, "downloads": -1, "filename": "anyloadump-0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "85852e056b76f0459a02a78d302cd7b1", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 7608, "upload_time": "2017-10-17T12:36:11", "url": "https://files.pythonhosted.org/packages/96/7a/2d3aac0e48162838e9a5630b7a0da98ecd257a8441a135555c12340b8c56/anyloadump-0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "6c27e2bf95e6c0fbc64af38e0577f101", "sha256": "73bc90514869f6a515f7e90f701c36b4f6284a4a53cb390ce7fcd707f0dda7e5" }, "downloads": -1, "filename": "anyloadump-0.1.tar.gz", "has_sig": false, "md5_digest": "6c27e2bf95e6c0fbc64af38e0577f101", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4702, "upload_time": "2017-10-17T12:36:12", "url": "https://files.pythonhosted.org/packages/94/fa/398002ff135abe64a26b84bf67927848e97532bda547a1d22d01feda6e6c/anyloadump-0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "85852e056b76f0459a02a78d302cd7b1", "sha256": "3a4b727e875309bd38b20bc6f358aefb49f535ee335366331330e2f4085b0a00" }, "downloads": -1, "filename": "anyloadump-0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "85852e056b76f0459a02a78d302cd7b1", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 7608, "upload_time": "2017-10-17T12:36:11", "url": "https://files.pythonhosted.org/packages/96/7a/2d3aac0e48162838e9a5630b7a0da98ecd257a8441a135555c12340b8c56/anyloadump-0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "6c27e2bf95e6c0fbc64af38e0577f101", "sha256": "73bc90514869f6a515f7e90f701c36b4f6284a4a53cb390ce7fcd707f0dda7e5" }, "downloads": -1, "filename": "anyloadump-0.1.tar.gz", "has_sig": false, "md5_digest": "6c27e2bf95e6c0fbc64af38e0577f101", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4702, "upload_time": "2017-10-17T12:36:12", "url": "https://files.pythonhosted.org/packages/94/fa/398002ff135abe64a26b84bf67927848e97532bda547a1d22d01feda6e6c/anyloadump-0.1.tar.gz" } ] }