{"id":13937714,"url":"https://github.com/nu11ptr/PyInstanceVars","last_synced_at":"2025-07-20T00:31:03.776Z","repository":{"id":67297279,"uuid":"8246444","full_name":"nu11ptr/PyInstanceVars","owner":"nu11ptr","description":"Automatically create Python instance variables from initializer arguments using a simple decorator","archived":false,"fork":false,"pushed_at":"2013-02-20T00:02:06.000Z","size":210,"stargazers_count":46,"open_issues_count":1,"forks_count":8,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-11-27T06:36:35.757Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nu11ptr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-02-17T05:18:05.000Z","updated_at":"2021-11-16T06:25:52.000Z","dependencies_parsed_at":"2023-02-20T17:00:27.102Z","dependency_job_id":null,"html_url":"https://github.com/nu11ptr/PyInstanceVars","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/nu11ptr/PyInstanceVars","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nu11ptr%2FPyInstanceVars","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nu11ptr%2FPyInstanceVars/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nu11ptr%2FPyInstanceVars/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nu11ptr%2FPyInstanceVars/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nu11ptr","download_url":"https://codeload.github.com/nu11ptr/PyInstanceVars/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nu11ptr%2FPyInstanceVars/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266048486,"owners_count":23868738,"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":[],"created_at":"2024-08-07T23:03:48.283Z","updated_at":"2025-07-20T00:31:03.542Z","avatar_url":"https://github.com/nu11ptr.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"PyInstanceVars\n==============\n\nA function decorator that automatically creates instance variables from function arguments. \n\nArguments can be omitted by adding them to the 'omit' list argument of the decorator.\nNames are retained on a one-to-one basis (i.e '_arg' --\u003e 'self._arg'). Passing\narguments as raw literals, using a keyword, or as defaults all work. If *args and/or\n**kwargs are used by the decorated function, they are not processed and must be handled\nexplicitly. \n\nBasic Usage\n===========\n\nThe simplest way to explain how to use it is with a quick code example:\n\n```python\n\u003e\u003e\u003e from instancevars import *\n\u003e\u003e\u003e class SimpleDemo(object):\n...     @instancevars\n...     def __init__(self, arg1, arg2, arg3):\n...             pass\n... \n\u003e\u003e\u003e simple = SimpleDemo(1, 2, 3)\n\u003e\u003e\u003e simple.arg1\n1\n\u003e\u003e\u003e simple.arg2\n2\n\u003e\u003e\u003e simple.arg3\n3\n```\n\nThis example shows how you can optionally skip arguments by adding them to the omit list. You can still manually\ndo whatever you need with them in the function body.\n\n```python\n\u003e\u003e\u003e from instancevars import *\n\u003e\u003e\u003e class TestMe(object):\n...     @instancevars(omit=['arg2_'])\n...     def __init__(self, _arg1, arg2_, arg3='test'):\n...             self.arg2 = arg2_ + 1\n...\n\u003e\u003e\u003e testme = TestMe(1, 2)\n\u003e\u003e\u003e testme._arg1\n1\n\u003e\u003e\u003e testme.arg2_\nTraceback (most recent call last):\n  File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\nAttributeError: 'TestMe' object has no attribute 'arg2_'\n\u003e\u003e\u003e testme.arg2\n3\n\u003e\u003e\u003e testme.arg3\n'test'\n\u003e\u003e\u003e\n```\n\nWhy?\n====\n\nBecause Python initializer functions can get lengthy doing nothing more than one-to-one variable assignment.\nLanguages such as Scala already have the ability to convert arguments to instance variables using 'val' or 'var'.\nGiven Python's reputation of being succinct and terse it seems like this should be builtin. \n\nSome may think this is 'unpythonic', but I would respectfully disagree. We've listed a decorator and \nan omit list denoting our intent, so I think we've been plenty 'explicit'. In my opinion, the terseness gained\nby the decorator aids readability. Just my opinion, decide for yourself.\n\nRequirements\n============\n\nIt has been tested under CPython 2.7/3.3, PyPy 1.9, and Jython 2.5/2.7.\n\nThere are no library dependencies other than the standard library.\n\nPerformance\n===========\n\nThanks to a contributed rewrite, performance is now only 30-40% worse than explicit initialization under CPython.\nThis is likely to be an acceptable amount of degradation for nearly all scenarios.\n\nCredits\n=======\n\nThe code was originally based on a great comment and snippet from StackOverflow (http://stackoverflow.com/questions/1389180/python-automatically-initialize-instance-variables).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnu11ptr%2FPyInstanceVars","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnu11ptr%2FPyInstanceVars","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnu11ptr%2FPyInstanceVars/lists"}