{"id":19741171,"url":"https://github.com/marrow/typecast","last_synced_at":"2025-02-27T22:45:08.260Z","repository":{"id":66821898,"uuid":"243091203","full_name":"marrow/typecast","owner":"marrow","description":"Utilize Python 3 function annotations for rich, structured typecasting, not just type validation and hinting, through direct specification and inference.","archived":false,"fork":false,"pushed_at":"2020-02-25T22:35:39.000Z","size":17,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"develop","last_synced_at":"2025-01-10T19:54:21.000Z","etag":null,"topics":["python","type-annotations","type-casting","type-coercion","type-inference"],"latest_commit_sha":null,"homepage":"","language":"Makefile","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/marrow.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"patreon":"GothAlice"}},"created_at":"2020-02-25T20:04:05.000Z","updated_at":"2020-04-29T01:38:34.000Z","dependencies_parsed_at":null,"dependency_job_id":"3ed647f6-89d9-4e17-8925-1e0ad253461d","html_url":"https://github.com/marrow/typecast","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":"marrow/marrow-package-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marrow%2Ftypecast","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marrow%2Ftypecast/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marrow%2Ftypecast/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marrow%2Ftypecast/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marrow","download_url":"https://codeload.github.com/marrow/typecast/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241070210,"owners_count":19904340,"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":["python","type-annotations","type-casting","type-coercion","type-inference"],"created_at":"2024-11-12T01:25:01.977Z","updated_at":"2025-02-27T22:45:08.242Z","avatar_url":"https://github.com/marrow.png","language":"Makefile","readme":"# Marrow Typecast\n\n[![][latestversion]][latestversion_] [![][ghtag]][ghtag_] [![][masterstatus]][masterstatus_] [![][mastercover]][mastercover_] [![][masterreq]][masterreq_] [![][ghwatch]][ghsubscription] [![][ghstar]][ghsubscription]\n\n\u003e © 2020 Alice Bevan-McGregor and contributors.\n\n\u003e https://github.com/marrow/typecast\n\nUtilize Python 3 function annotations for rich, structured typecasting, not just type validation and hinting, through direct specification and inference.\n\n\n## Contents\n\n1. [Overview](#overview)\n\n2. [Installation](#installation)\n\n\t1. [Development Version](#development-version)\n\n3. [Getting Started](#getting-started)\n\n4. [Version History](#version-history)\n\n5. [License](#license)\n\n\n## Overview\n\nA fairly substantial number of packages exist for the purpose of de-serializing data coming in from the web. Many utilize dedicated schemas, or declarative mechanisms to explicitly define a data model for the purpose of listening to that side of the conversation, sometimes also incorporating re-serialization out in various ways such as form widget libraries, JSON data, \u0026c. Most use decorators to serve the role of \"annotating\" functions. Many of these were developed with legacies starting in Python 2, prior to the addition of [function annotations](https://www.python.org/dev/peps/pep-3107/) in Python 3.\n\nUntil such time as [PEP 593](https://www.python.org/dev/peps/pep-0593/) (_Flexible function and variable annotations_) hits release and wide adoption in Python 3.9, this package aims to provide such functionality explicitly, where annotations are explicit, and through inference more generally.  There will be a bias towards the context of web-based and command-line invocation.  In the abstract, this can eliminate the need for \"form libraries\" et. al. for resolving simpler or more common problems.\n\n\n## Installation\n\nInstalling `marrow.typecast` is easy, just execute the following in a terminal:\n\n\tpip install marrow.typecast\n\n**Note:** We *strongly* recommend always using a container, virtualization, or sandboxing environment of some kind when developing using Python. We highly recommend use of the Python standard [`venv` (_\"virtual environment\"_) mechanism][venv].\n\nIf you add `marrow.typecast` to the `install_requires` argument of the call to `setup()` in your application's `setup.py` or `setup.cfg` files, `marrow.typecast` will be automatically installed and made available when your own application or library is installed. Use `marrow.typecast ~= 1.0.0` to get all bug fixes for the current release while ensuring that large breaking changes are not installed by limiting to the same major/minor, \u003e= the given patch level.\n\nThis package has the following dependencies:\n\n* A Python interpreter compatible with CPython 3.7 and or newer, i.e. official CPython or Pypy.\n\n\n### Development Version\n\n\u003e [![][developstatus]][developstatus_] [![][developcover]][developcover_] [![][ghsince]][ghsince_] [![][ghissues]][ghissues_] [![][ghfork]][ghfork_]\n\nDevelopment takes place on [GitHub][github] in the [typecast][repo] project. Issue tracking, documentation, and downloads are provided there.\n\nInstalling the current development version requires [Git][git]), a distributed source code management system. If you have Git you can run the following to download and *link* the development version into your Python runtime:\n\n\tgit clone https://github.com/marrow/typecast.git\n\tpip install -e 'typecast[development]'\n\nYou can then upgrade to the latest version at any time, from within that source folder:\n\n\tgit pull\n\tpip install -e '.[development]'\n\nIf you would like to make changes and contribute them back to the project, fork the GitHub project, make your changes, and submit a pull request. This process is beyond the scope of this documentation; for more information see [GitHub's documentation][ghhelp].\n\n\n## Getting Started\n\nGeneral usage involves defining a function or method with annotations and decorating it using the `cast` decorator.\n\n```py\nfrom typing import Optional, Set\n\nfrom marrow.typecast import cast\n\n\n@cast\ndef sample(name:str, age:int, tags:Optional[Set[str]]=None):\n\treturn name, age, tags\n```\n\nAttempts to typecast will raise `TypeError` and `ValueError` exceptions where appropriate to indicate a fundamental incompatibility or content incompatibility, respectively. For example, passing a literal `None` as the `age` parameter will result in a `TypeError` exception. Passing the string `\"bob\"` will result in a `ValueError`, as that string is not number-like, but number-like strings are usable.\n\nWhen invoked, values will be recursively cast as needed:\n\n```py\n\u003e\u003e\u003e sample(\"amcgregor\", \"27\", tags=[\"27\", 42, 53])\n(\"amcgregor\", 27, {\"27\", \"42\", \"53\"})\n```\n\n\n### Framework Usage\n\nYou may wish to expose functions through an external interface such as a web-based API or command line script. If the framework you are using is aware of / utilizes this library or if this library provides a plugin suitable for integrated use, this can eliminate any direct need for the decorator.  This will theoretically save a stack frame and the overhead of a nested function call if your framework will do this already.\n\nThis is generally unnecessary, however, as \"aware\" integrations will bypass the decoration and that overhead anyway. Permitting you to utilize your code both as a native Python API, and as a web-based API, command-line script, etc. as desired. Needs vary.\n\n\n## Version History\n\nThis project has yet to make any releases. When it does, each release will be documented here with a sub-section for the version, and a bulleted list of itemized changes tagged with the kind of change, e.g. *fixed*, *added*, *removed*, or *deprecated*. Each will also include relevant links to the release on GitHub, and any involved issues / pull requests.\n\n\n## License\n\nMarrow Typecast has been released under the MIT Open Source license.\n\n### The MIT License\n\nCopyright © 2020 Alice Bevan-McGregor and contributors.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n\n[venv]: https://docs.python.org/3/tutorial/venv.html\n\n[git]: http://git-scm.com/\n[repo]: https://github.com/marrow/typecast/\n[github]: https://github.com/\n[ghhelp]: https://help.github.com/\n\n\n[ghwatch]: https://img.shields.io/github/watchers/marrow/typecast.svg?style=social\u0026label=Watch \"Subscribe to project activity on GitHub.\"\n[ghstar]: https://img.shields.io/github/stars/marrow/typecast.svg?style=social\u0026label=Star \"Star this project on GitHub.\"\n[ghsubscription]: https://github.com/marrow/typecast/subscription\n[ghfork]: https://img.shields.io/github/forks/marrow/typecast.svg?style=social\u0026label=Fork \"Fork this project on Github.\"\n[ghfork_]: https://github.com/marrow/typecast/fork\n\n[masterstatus]: http://img.shields.io/travis/marrow/typecast/master.svg?style=flat \"Production build status.\"\n[masterstatus_]: https://travis-ci.org/marrow/typecast/branches\n[mastercover]: http://img.shields.io/codecov/c/github/marrow/typecast/master.svg?style=flat \"Production test coverage.\"\n[mastercover_]: https://codecov.io/github/marrow/typecast?branch=master\n[masterreq]: https://img.shields.io/requires/github/marrow/typecast.svg \"Status of production dependencies.\"\n[masterreq_]: https://requires.io/github/marrow/typecast/requirements/?branch=master\n\n[developstatus]: http://img.shields.io/travis/marrow/typecast/develop.svg?style=flat \"Development build status.\"\n[developstatus_]: https://travis-ci.org/marrow/typecast/branches\n[developcover]: http://img.shields.io/codecov/c/github/marrow/typecast/develop.svg?style=flat \"Development test coverage.\"\n[developcover_]: https://codecov.io/github/marrow/typecast?branch=develop\n[developreq]: https://img.shields.io/requires/github/marrow/typecast.svg \"Status of development dependencies.\"\n[developreq_]: https://requires.io/github/marrow/typecast/requirements/?branch=develop\n\n[ghissues]: http://img.shields.io/github/issues-raw/marrow/typecast.svg?style=flat \"Github Issues\"\n[ghissues_]: https://github.com/marrow/typecast/issues\n[ghsince]: https://img.shields.io/github/commits-since/marrow/typecast/1.0.svg \"Changes since last release.\"\n[ghsince_]: https://github.com/marrow/typecast/commits/develop\n[ghtag]: https://img.shields.io/github/tag/marrow/typecast.svg \"Latest Github tagged release.\"\n[ghtag_]: https://github.com/marrow/typecast/tree/1.0\n[latestversion]: http://img.shields.io/pypi/v/marrow.typecast.svg?style=flat \"Latest released version on Pypi.\"\n[latestversion_]: https://pypi.python.org/pypi/marrow.typecast\n\n[cake]: http://img.shields.io/badge/cake-lie-1b87fb.svg?style=flat\n","funding_links":["https://patreon.com/GothAlice"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarrow%2Ftypecast","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarrow%2Ftypecast","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarrow%2Ftypecast/lists"}