{"action":"created","issue":{"url":"https://api.github.com/repos/google/flatbuffers/issues/202","labels_url":"https://api.github.com/repos/google/flatbuffers/issues/202/labels{/name}","comments_url":"https://api.github.com/repos/google/flatbuffers/issues/202/comments","events_url":"https://api.github.com/repos/google/flatbuffers/issues/202/events","html_url":"https://github.com/google/flatbuffers/issues/202","id":77213160,"number":202,"title":"More handy python interface","user":{"login":"layzerar","id":652101,"avatar_url":"https://avatars.githubusercontent.com/u/652101?v=3","gravatar_id":"","url":"https://api.github.com/users/layzerar","html_url":"https://github.com/layzerar","followers_url":"https://api.github.com/users/layzerar/followers","following_url":"https://api.github.com/users/layzerar/following{/other_user}","gists_url":"https://api.github.com/users/layzerar/gists{/gist_id}","starred_url":"https://api.github.com/users/layzerar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/layzerar/subscriptions","organizations_url":"https://api.github.com/users/layzerar/orgs","repos_url":"https://api.github.com/users/layzerar/repos","events_url":"https://api.github.com/users/layzerar/events{/privacy}","received_events_url":"https://api.github.com/users/layzerar/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":18,"created_at":"2015-05-17T04:41:13Z","updated_at":"2015-06-28T17:03:32Z","closed_at":null,"body":"As `python` is weak typing language, a `dumps` function like json is more handy for users.\r\n\r\nI did some work for it recently, you can find the commit here https://github.com/layzerar/flatbuffers/tree/handy_python_interface.\r\n\r\nMy pull request will contain some destructive changes. If it's okay, I will submit a pull request.\r\n\r\nThe main changes:\r\n+ wrap the attribute accessing function with attribute descriptor(`__get__`), so we can access the attribute just calling `monster.hp`\r\n+ wrap the building process, so we can build a buffer just calling `Monster.Create(builder, {'hp': 80})` \r\n\r\nProps:\r\n+ handy interface\r\n+ better performance (about 20% improvement in reading)\r\n+ small generated code\r\n+ make it more easy to got better performance through c extension\r\n\r\nGenerated code would like this:\r\n```python\r\nimport flatbuffers\r\n\r\nclass Stat(object):\r\n    __slots__ = ['_tab']\r\n\r\n    # Stat\r\n    def Init(self, buf, pos):\r\n        self._tab = flatbuffers.Table(buf, pos)\r\n\r\n    id = flatbuffers.StringProperty(4)\r\n    val = flatbuffers.Int64Property(6, default=0)\r\n    count = flatbuffers.Uint16Property(8, default=0)\r\n\r\n    @classmethod\r\n    def Create(cls, builder, d):\r\n        d_get = d.get\r\n        builder.StartObject(3)\r\n        v = d_get('id', None)\r\n        if v is not None:\r\n            v = builder.CreateString(v)\r\n            builder.PrependUOffsetTRelativeSlot(0, v, 0)\r\n        v = d_get('val', None)\r\n        if v is not None:\r\n            builder.PrependInt64Slot(1, v, 0)\r\n        v = d_get('count', None)\r\n        if v is not None:\r\n            builder.PrependUint16Slot(2, v, 0)\r\n        o = builder.EndObject()\r\n        builder.Finish(o)\r\n        return o\r\n```\r\n\r\nBuilding code would like this:\r\n```python\r\nb = flatbuffers.Builder(0)\r\ntest = Monster.Monster.Create(b, {'name': \"Fred\"})  # TODO: union need more work\r\nd = {\r\n    'pos': {'x': 1.0, 'y': 2.0, 'z': 3.0, 'test1': 3.0, 'test2': 2,\r\n            'test3': {'a': 5, 'b': 6}},\r\n    'hp': 80,\r\n    'name': \"MyMonster\",\r\n    'inventory': [4, 3, 2, 1, 0],\r\n    'test_type': 1,\r\n    'test': test,\r\n    'test4': [{'a': 10, 'b': 20}, {'a': 30, 'b': 40}],\r\n    'testarrayofstring': [\"test2\", \"test1\"]\r\n}\r\nMonster.Monster.Create(b, d)\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/google/flatbuffers/issues/comments/116299104","html_url":"https://github.com/google/flatbuffers/issues/202#issuecomment-116299104","issue_url":"https://api.github.com/repos/google/flatbuffers/issues/202","id":116299104,"user":{"login":"rw","id":21367,"avatar_url":"https://avatars.githubusercontent.com/u/21367?v=3","gravatar_id":"","url":"https://api.github.com/users/rw","html_url":"https://github.com/rw","followers_url":"https://api.github.com/users/rw/followers","following_url":"https://api.github.com/users/rw/following{/other_user}","gists_url":"https://api.github.com/users/rw/gists{/gist_id}","starred_url":"https://api.github.com/users/rw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rw/subscriptions","organizations_url":"https://api.github.com/users/rw/orgs","repos_url":"https://api.github.com/users/rw/repos","events_url":"https://api.github.com/users/rw/events{/privacy}","received_events_url":"https://api.github.com/users/rw/received_events","type":"User","site_admin":false},"created_at":"2015-06-28T17:03:32Z","updated_at":"2015-06-28T17:03:32Z","body":"@layzerar What happens if a user installs Cython after installing flatbuffers? Will the detection happen at install time or at run time?"}}