{ "info": { "author": "Aden Herold", "author_email": "aden.herold1@gmail.com", "bugtrack_url": null, "classifiers": [], "description": "# typemallow\n_An elegant and automatic solution for generating/outputting Typescript interfaces from your Marshmallow Schemas_\n\nI created this Package out of necessity for one of my own projects. Rather than keeping it to myself, I thought it would be helpful for other developers and my own future projects if I uploaded it.\n\n### Usage:\n\n_Using typemallow is simple._\n\nFirst, install the package \n`pip install typemallow`\n\nNext, for your Marshmallow schemas that you wish to generate Typescript interfaces for, simply import `ts_interface` and `generate_ts` from the `typemallow` module, and prepend the `@ts_interface()` class decorator to your Marshmallow schema class.\n\nAll that is required to generate your Typescript interfaces is to call the `generate_ts()` function, and provide a filepath as a parameter to output the result.\n\n_main.py_\n```python\nfrom typemallow import ts_interface, generate_ts\n\n\n@ts_interface()\nclass Foo(Schema):\n some_field = fields.Str()\n another_field = fields.Date()\n\n\ngenerate_ts('./output.ts')\n```\n\n_output.ts_\n```typescript\nexport interface Foo {\n some_field: string;\n another_field: date;\n}\n```\n\n_typemallow_ even supports Nested Schema fields!\n\n_main.py_\n```python\nfrom typemallow import ts_interface, generate_ts\n\n@ts_interface()\nclass Foo(Schema):\n some_field = fields.Str()\n another_field = fields.Date()\n\n@ts_interface()\nclass Bar(Schema):\n foo = fields.Nested(Foo)\n foos = fields.Nested(Foo, many=True)\n bar_field = fields.Str()\n```\n_output.ts_\n```typescript\nexport interface Foo {\n some_field: string;\n another_field: date;\n}\n\nexport interface Bar {\n foo: Foo;\n foos: Foo[];\n bar_field: string;\n}\n```\n\n### Extended Usage:\nThe `@ts_interface()` decorator function accepts an optional parameter, _context_, which defaults to... well... 'default'.\n\n\"_Why is this the case?_\" \n\nWhen a Marshmallow Schema is identified with with `@ts_interface` decorator, it is added to a list in a dictionary of schemas, with the dictionary key being the value provided to the _context_ parameter. If you were to provide different contexts for each schema, additional keys will be created if they do not exist, or the schema will simply be appended to the list at the existing key.\n\nThis comes in handy, as the `generate_ts()` function _also_ accepts an optional _context_ parameter, which will filter only schemas in the dictionary at the specific key.\n\nThis is useful if you wish to output different contexts to different files, e.g.\n\n_main.py_\n```python\n...\nfrom typemallow import ts_interface, generate_ts\n\n@ts_interface(context='internal')\nclass Foo(Schema):\n foo = fields.Str()\n\n\n@ts_interface(context='internal')\nclass Bar(Schema):\n bar = fields.Str()\n \n\n@ts_interface(context='external')\nclass FooBar(Schema):\n foo_bar = fields.Str()\n\n\n''' \nwe're telling typemallow that we only want to generate interfaces from Schemas with \nan 'internal' context to './internal.ts' \n'''\ngenerate_ts('./internal.ts', context='internal')\n\n''' \nonly generate interfaces from Schemas with an 'external' context to './external.ts' \n'''\ngenerate_ts('./external.ts', context='external')\n```\n\n_internal.ts_\n```typescript\nexport interface Foo {\n foo: string;\n}\n\nexport interface Bar {\n bar: string;\n}\n```\n\n_external.ts_\n```typescript\nexport interface FooBar {\n foo_bar: string;\n}\n```", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/adenh93/typemallow", "keywords": "Marshmallow,Typescript,Python,Flask,Django", "license": "", "maintainer": "", "maintainer_email": "", "name": "typemallow", "package_url": "https://pypi.org/project/typemallow/", "platform": "any", "project_url": "https://pypi.org/project/typemallow/", "project_urls": { "Homepage": "https://github.com/adenh93/typemallow" }, "release_url": "https://pypi.org/project/typemallow/0.0.4/", "requires_dist": null, "requires_python": "", "summary": "An elegant and automatic solution for generating/outputting Typescript interfaces from your Marshmallow Schemas.", "version": "0.0.4" }, "last_serial": 5361957, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "d3d6e5ce68f9cdfdc7de221e9d2be9c3", "sha256": "30352050392c212ce5c85a676f09769df14f99d74e3a9641ce12a42fbc861bae" }, "downloads": -1, "filename": "typemallow-0.0.1.tar.gz", "has_sig": false, "md5_digest": "d3d6e5ce68f9cdfdc7de221e9d2be9c3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2952, "upload_time": "2019-06-03T12:38:03", "url": "https://files.pythonhosted.org/packages/a8/21/b8d534bdd87e83c5445a86ee26bedb6c1cb5a5a0c7b30d904cc762ed0eb4/typemallow-0.0.1.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "a28e68eadd9fafd60e5f7885c2e5e23a", "sha256": "5ae47cf130d1239aeb8e5e58411594019c849c79c771cd59722b6c589f408b49" }, "downloads": -1, "filename": "typemallow-0.0.2.tar.gz", "has_sig": false, "md5_digest": "a28e68eadd9fafd60e5f7885c2e5e23a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3536, "upload_time": "2019-06-04T02:02:13", "url": "https://files.pythonhosted.org/packages/ad/d0/c7c1c11642a22ccf7458b2b11258f0381132bc55ba045d82b856adfdf32d/typemallow-0.0.2.tar.gz" } ], "0.0.3": [ { "comment_text": "", "digests": { "md5": "d4e40dcd784c329dc1186fc4312f8494", "sha256": "9ec715698b39e807778c43881d7d948831306f78d3fd8063aa606700ecc145f2" }, "downloads": -1, "filename": "typemallow-0.0.3.tar.gz", "has_sig": false, "md5_digest": "d4e40dcd784c329dc1186fc4312f8494", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3540, "upload_time": "2019-06-04T04:11:05", "url": "https://files.pythonhosted.org/packages/cf/2b/8540104085047b5034f95f3167e58b3bf08ed76539cc13553c306ad7c813/typemallow-0.0.3.tar.gz" } ], "0.0.4": [ { "comment_text": "", "digests": { "md5": "6514c0088b9738069cf5df4bc12869b8", "sha256": "2e065ed0a710d10047d62113f1874637a24af344f03267ac99f6c4615b08aecc" }, "downloads": -1, "filename": "typemallow-0.0.4.tar.gz", "has_sig": false, "md5_digest": "6514c0088b9738069cf5df4bc12869b8", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3539, "upload_time": "2019-06-05T10:25:36", "url": "https://files.pythonhosted.org/packages/56/30/8e0870854f1fba34c46dbcff50d5de6f74612c4c564d2ed98e023f894f3a/typemallow-0.0.4.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "6514c0088b9738069cf5df4bc12869b8", "sha256": "2e065ed0a710d10047d62113f1874637a24af344f03267ac99f6c4615b08aecc" }, "downloads": -1, "filename": "typemallow-0.0.4.tar.gz", "has_sig": false, "md5_digest": "6514c0088b9738069cf5df4bc12869b8", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3539, "upload_time": "2019-06-05T10:25:36", "url": "https://files.pythonhosted.org/packages/56/30/8e0870854f1fba34c46dbcff50d5de6f74612c4c564d2ed98e023f894f3a/typemallow-0.0.4.tar.gz" } ] }