{"id":47874891,"url":"https://github.com/suzaku/plain_obj","last_synced_at":"2026-04-04T01:10:31.211Z","repository":{"id":57453268,"uuid":"102235284","full_name":"suzaku/plain_obj","owner":"suzaku","description":"A faster alternative to namedtuple.","archived":false,"fork":false,"pushed_at":"2017-09-08T13:45:15.000Z","size":12,"stargazers_count":18,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-09-20T01:00:03.014Z","etag":null,"topics":["library","namedtuple","python","python3"],"latest_commit_sha":null,"homepage":"https://github.com/suzaku/plain_obj","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/suzaku.png","metadata":{"files":{"readme":"README.rst","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}},"created_at":"2017-09-03T02:09:33.000Z","updated_at":"2023-12-13T16:24:17.000Z","dependencies_parsed_at":"2022-08-29T08:41:41.660Z","dependency_job_id":null,"html_url":"https://github.com/suzaku/plain_obj","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/suzaku/plain_obj","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/suzaku%2Fplain_obj","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/suzaku%2Fplain_obj/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/suzaku%2Fplain_obj/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/suzaku%2Fplain_obj/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/suzaku","download_url":"https://codeload.github.com/suzaku/plain_obj/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/suzaku%2Fplain_obj/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31383726,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-03T23:20:52.058Z","status":"ssl_error","status_checked_at":"2026-04-03T23:20:51.675Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["library","namedtuple","python","python3"],"created_at":"2026-04-04T01:10:30.611Z","updated_at":"2026-04-04T01:10:31.148Z","avatar_url":"https://github.com/suzaku.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"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\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 µs per loop\n\n    In [4]: %timeit plain_obj.new_type('Point', ['x', 'y', 'z'])\n    10000 loops, best of 3: 97.8 µs 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 µs ± 3.82 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n\n    In [4]: %timeit plain_obj.new_type('Point', ['x', 'y', 'z'])\n    53.5 µs ± 1.2 µs per loop (mean ± 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 ± 2.5 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)\n\n    In [8]: %timeit NewPoint(1, 2, 3)\n    438 ns ± 5.53 ns per loop (mean ± 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 ± 2.52 ns per loop (mean ± 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 ± 1.7 ns per loop (mean ± 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\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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsuzaku%2Fplain_obj","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsuzaku%2Fplain_obj","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsuzaku%2Fplain_obj/lists"}