https://github.com/xomicsdatascience/typomancy
Toolkit for converting HTML string input into Python types indicated by TypeHints
https://github.com/xomicsdatascience/typomancy
flask html json python3 typehint
Last synced: 4 months ago
JSON representation
Toolkit for converting HTML string input into Python types indicated by TypeHints
- Host: GitHub
- URL: https://github.com/xomicsdatascience/typomancy
- Owner: xomicsdatascience
- License: mit
- Created: 2023-07-18T18:57:16.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2025-05-29T18:13:49.000Z (about 1 year ago)
- Last Synced: 2025-05-29T19:43:24.680Z (about 1 year ago)
- Topics: flask, html, json, python3, typehint
- Language: Python
- Homepage:
- Size: 30.3 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Typomancy
###### "Cheese or typos, I'm not sure."
Typomancy is a Python package for parsing string inputs and converting them into data types expected by a Python
function or class using type annotations.
The purpose is to facilitate the interaction between user inputs supplied through a public-facing interface (e.g., HTML page) and
a Python-based backend. Since end users shouldn't need to know about expected datatypes, their inputs are loosely-structured
strings. The typical solution would be for functions to parse the input and perform the typecasting. This is fine, but in the case
of inherited classes, it seems cleaner to perform the typecasting generically to avoid requiring all children to do similar
typecasting.
The package makes use of Python's `typing` library in addition to Python's built-in types (`int`, `str`, `bool`, etc.). Typomancy
performs opinionated typecasting for non-specific type annotations, casting the argument to a built-in type that satisfies the
annotation. For example, `Collection` and `Iterable` would cause the input to be cast to `tuple`. Similarly, `Collection[str]`
causes the input to be cast to a `tuple` with `str` elements.