cooked_input is a Python package for getting, cleaning, converting, and validating input.
If you think of input (raw_input in legacy Python) as raw input, then this is cooked input.
cooked_input provides a simple and safe way to get validated command line input that ranges from the simplest
of Python programs to sophisticated database driven applications. Beginner's can use the provided convenience classes
to get simple inputs from the user. Following the quick start guide
you can be up and running in minutes.
More advanced users can easily create custom classes for sophisticated cleaning and validation. Cooked_input can
also be used to create menus and data tables. The latter tutorials
(part one and
part two) and examples show several examples ranging from
simple to sophisticated calls.
Cooked_input also provides a pathway to use the same cleaning and validation logic used in the command line
for validating web or GUI based inputs.
The documentation is available at: http://cooked-input.readthedocs.io/en/latest/
cooked_input requires Python 3.10 or later, and has been tested through Python 3.14. Python 2 is no longer supported (the last release supporting it is v0.5.4).
v0.7.0 is a large release by volume of change, even though it adds no new functionality. It
is almost entirely work on the inside of the package. Every function, method and class was
annotated with types, and a py.typed marker now ships so downstream projects actually see
them; the test suite went from 86 tests at 79.6% coverage to 661 at 100%; and the two largest
modules were split along the seam they already had. Reading essentially all of the code that way
turned up thirty-two real defects that had been sitting behind an untyped signature or an
untested line, and those fixes are the bulk of the release.
There are breaking changes. Most code will not notice, but they are worth a look before upgrading:
DecimalConvertornow honoursprecisionandrounding, which it had been ignoring, soget_money(precision=2)returns different numbers than it used to.Table.scroll_up_one_rowandTable.scroll_down_one_rowhad their bodies the wrong way round and now move the view in the direction they are named for.get_menureturns'exit'where it used to hand back aTableItem, andTable.get_table_choicereturns None when the exit row is chosen.- A blank line at a
required=Trueprompt is reported througherror_callbackand counts againstretries, instead of being skipped in silence -- which had been an infinite loop. in_all,in_anyandnot_inare no longer importable fromcooked_input. They were always internal plumbing and appeared in no documentation.validate()is unaffected.- The module-level validation helpers, and
SimpleValidator, now return a realboolrather than passing a validator's truthy return value through, and return True rather than None when there is nothing to validate. GetInputand everyget_*function take their options as named keyword-only parameters instead of a**optionsdictionary. An unrecognised option raises aTypeErrorrather than logging a warning and carrying on with the default, soget_int(promt="Age?")is now reported instead of quietly asking the wrong question. Code that builds an options dictionary still works by unpacking it:get_int(**options).Table,create_table,get_menu,Table.get_table_choiceandget_table_inputchanged the same way. An unrecognised option raises aTypeErrorrather than being silently ignored -- which is how two bugs in the shipped examples had gone unnoticed.Cleaner,ConvertorandValidatorare now real abstract base classes. A subclass that never implemented__call__raisesTypeErrorwhen instantiated, where before it silently returned None from every call.- A single string given to
AnyOfValidatororNoneOfValidatoris now one choice rather than being iterated one character at a time.
See CHANGELOG.rst for the full list, including the defects the type checker found and what each of them affected.
pip install cooked_input
Project information and source code is available at: https://github.com/lwanger/cooked_input
The best way to get started is to read the quick start at: http://cooked-input.readthedocs.io/en/latest/quick_start.html
After that, more advanced usage can be learned from the tutorial at: http://cooked-input.readthedocs.io/en/latest/tutorial.html