{ "info": { "author": "Satoru Logic", "author_email": "satorulogic@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "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.5", "Programming Language :: Python :: 3.6" ], "description": "plain_obj\n##########\n\n.. image:: https://travis-ci.org/suzaku/plain_obj.svg?branch=master\n :target: https://travis-ci.org/suzaku/plain_obj\n.. image:: https://img.shields.io/pypi/v/plain_obj.svg\n :target: https://pypi.python.org/pypi/plain_obj\n\nA faster alternative to namedtuple.\n\nBasic Usage\n***********\n\nCreation\n========\n\n.. code-block:: python\n\n import plain_obj\n Config = plain_obj.new_type('Config', 'is_debug, skips_dist, run_tests')\n config = Config(True, False, True)\n if config.is_debug:\n print(\"This is a verbose debugging message.\")\n\nMake a dict\n===========\n\n.. code-block:: python\n \n config.as_dict()\n\nUnpacking\n=========\n\n.. code-block:: python\n \n is_debug, _, run_tests = config\n\n\n.. image:: https://app.codesponsor.io/embed/MY7qFCdB7bDgiBqdjtV9ASYi/suzaku/plain_obj.svg\n :width: 888px\n :height: 68px\n :alt: Sponsor\n :target: https://app.codesponsor.io/link/MY7qFCdB7bDgiBqdjtV9ASYi/suzaku/plain_obj\n\n\nWhen to use ``plain_obj`` instead of ``namedtuple``?\n************************************************************\n\n**When faster creation time matters to you.**\n\nComparing ``plain_obj`` with ``namedtuple`` in *Python 2.7*:\n\n.. code-block:: python\n\n In [3]: %timeit collections.namedtuple('Point', ['x', 'y', 'z'])\n 1000 loops, best of 3: 338 \u00b5s per loop\n\n In [4]: %timeit plain_obj.new_type('Point', ['x', 'y', 'z'])\n 10000 loops, best of 3: 97.8 \u00b5s per loop\n\n In [5]: Point = collections.namedtuple('Point', ['x', 'y', 'z'])\n\n In [6]: NewPoint = plain_obj.new_type('Point', ['x', 'y', 'z'])\n\n In [7]: %timeit Point(1, 2, 3)\n The slowest run took 7.99 times longer than the fastest. This could mean that an intermediate result is being cached.\n 1000000 loops, best of 3: 507 ns per loop\n\n In [8]: %timeit NewPoint(1, 2, 3)\n The slowest run took 6.70 times longer than the fastest. This could mean that an intermediate result is being cached.\n 1000000 loops, best of 3: 462 ns per loop\n\n In [9]: p = Point(1, 2, 3)\n\n In [10]: new_p = NewPoint(1, 2, 3)\n\n In [11]: %timeit p.x, p.y, p.z\n The slowest run took 9.92 times longer than the fastest. This could mean that an intermediate result is being cached.\n 1000000 loops, best of 3: 408 ns per loop\n\n In [12]: %timeit new_p.x, new_p.y, new_p.z\n The slowest run took 11.70 times longer than the fastest. This could mean that an intermediate result is being cached.\n 10000000 loops, best of 3: 163 ns per loop\n\nComparing ``plain_obj`` with ``namedtuple`` in *Python 3.6*:\n\n.. code-block:: python\n\n In [3]: %timeit collections.namedtuple('Point', ['x', 'y', 'z'])\n 382 \u00b5s \u00b1 3.82 \u00b5s per loop (mean \u00b1 std. dev. of 7 runs, 1000 loops each)\n\n In [4]: %timeit plain_obj.new_type('Point', ['x', 'y', 'z'])\n 53.5 \u00b5s \u00b1 1.2 \u00b5s per loop (mean \u00b1 std. dev. of 7 runs, 10000 loops each)\n\n In [5]: Point = collections.namedtuple('Point', ['x', 'y', 'z'])\n\n In [6]: NewPoint = plain_obj.new_type('Point', ['x', 'y', 'z'])\n\n In [7]: %timeit Point(1, 2, 3)\n 521 ns \u00b1 2.5 ns per loop (mean \u00b1 std. dev. of 7 runs, 1000000 loops each)\n\n In [8]: %timeit NewPoint(1, 2, 3)\n 438 ns \u00b1 5.53 ns per loop (mean \u00b1 std. dev. of 7 runs, 1000000 loops each)\n\n In [9]: p = Point(1, 2, 3)\n\n In [10]: new_p = NewPoint(1, 2, 3)\n\n In [11]: %timeit p.x, p.y, p.z\n 282 ns \u00b1 2.52 ns per loop (mean \u00b1 std. dev. of 7 runs, 1000000 loops each)\n\n In [12]: %timeit new_p.x, new_p.y, new_p.z\n 148 ns \u00b1 1.7 ns per loop (mean \u00b1 std. dev. of 7 runs, 10000000 loops each)\n\nAs you can see, it's faster in all cases including *type creation*, *object instantiation* and *attribute access*.\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/suzaku/plain_obj", "keywords": "tuple", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "plain_obj", "package_url": "https://pypi.org/project/plain_obj/", "platform": "", "project_url": "https://pypi.org/project/plain_obj/", "project_urls": { "Homepage": "https://github.com/suzaku/plain_obj" }, "release_url": "https://pypi.org/project/plain_obj/0.1.2/", "requires_dist": null, "requires_python": "", "summary": "A faster alternative to namedtuple.", "version": "0.1.2" }, "last_serial": 3144995, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "2234f590589423f64daec1dbdaef863e", "sha256": "6b127d384afbd24f657c504fcba5310620cea133ba86d4128ca97899b4e430c9" }, "downloads": -1, "filename": "plain_obj-0.1.0.tar.gz", "has_sig": false, "md5_digest": "2234f590589423f64daec1dbdaef863e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 1710, "upload_time": "2017-09-03T04:24:29", "url": "https://files.pythonhosted.org/packages/5e/b6/5a432e5be10136c5425e43df46d8401d396eb12c75dd6a8a43b2a41fbe6c/plain_obj-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "5b466f9ca66ae27ffe15594fd3383a41", "sha256": "9c591dc0315e42f9160a63d6b82b23287bc469ea21f98d729e0c8471cacd761e" }, "downloads": -1, "filename": "plain_obj-0.1.1.tar.gz", "has_sig": false, "md5_digest": "5b466f9ca66ae27ffe15594fd3383a41", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2725, "upload_time": "2017-09-03T05:16:40", "url": "https://files.pythonhosted.org/packages/f8/e7/10af534d297642a1e967b73b6c82a5fd83561680e6795dcff2568385c4e5/plain_obj-0.1.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "37992efa6799d1366cd4b8431f64d67e", "sha256": "321ecd8362795bdb82a3b67ad4bf375eae55041124d42953fac4c9efc22354ee" }, "downloads": -1, "filename": "plain_obj-0.1.2.tar.gz", "has_sig": false, "md5_digest": "37992efa6799d1366cd4b8431f64d67e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2799, "upload_time": "2017-09-03T08:52:42", "url": "https://files.pythonhosted.org/packages/7a/ba/2d9ae6243fd7caa94e6c3c70f3ad830d33323d4c3d340c56a5125bb23ca0/plain_obj-0.1.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "37992efa6799d1366cd4b8431f64d67e", "sha256": "321ecd8362795bdb82a3b67ad4bf375eae55041124d42953fac4c9efc22354ee" }, "downloads": -1, "filename": "plain_obj-0.1.2.tar.gz", "has_sig": false, "md5_digest": "37992efa6799d1366cd4b8431f64d67e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2799, "upload_time": "2017-09-03T08:52:42", "url": "https://files.pythonhosted.org/packages/7a/ba/2d9ae6243fd7caa94e6c3c70f3ad830d33323d4c3d340c56a5125bb23ca0/plain_obj-0.1.2.tar.gz" } ] }