Formula Prompt
This library let's you define formulas that you can later evaluate in your command line. I use this library for school work that requires repetitive calculations or calculations needing a computer.
Example
Here I define two formulas. Notice the @register_formula(...) decorator
that registers the formulas with the library.
from formula_prompt import *
@register_formula([NumInput("side length")])
def volume_of_cube(s):
return s ** 3
@register_formula([NumInput("length"), NumInput("width")])
def area_of_rectangle(length, width):
return length * width
Now that the library has registered the formulas, I can launch the prompt.
launch_prompt()
The prompt lets you pick a formula and evaluate it.
0: area_of_rectangle
1: volume_of_cube
2: quit
Pick a formula:
>>> 1
Input side length:
>>> 3
volume_of_cube:
27.0
For more examples, look at the /examples folder on GitHub.
How to use this library
-
Install the library by running:
pip install formula-prompt -
Write your formulas (see example above).
-
Add the
@register_formula(...)decorator (see below). -
Call
launch_prompt().
Using @register_formula(...)
@register_formula(...) is a decorator that takes in a few parameters.
| name | Required | Description |
|---|---|---|
func_inputs |
Yes | A list of objects describing the inputs to your formula (see allowed formula inputs section below). |
decimal_places |
No. Defaults to 4. | Decimal places to round the results of your formula to. Specify None to disable rounding. |
name |
No. Defaults to the function name. | Lets you set the name that will be displayed in the prompt. Names containing dots (.) will be considered folders. For example, volumes.cube will place the formula in a volumes folder and display the formula as cube. |
Allowed formula inputs
You can specify three types of inputs.
-
NumInput: For inputs that accepts a single floating-point number. -
IntInput: For inputs that accept a single integer. -
ListInput: For inputs that accept a list of floating-point numbers.
You can use optional=True to allow skipping the input (this will pass None
to your function).
Here's an example.
@register_formula([
IntInput("first optional input", optional=True),
NumInput("second non-optional input")
])
def some_funtion(first_integer_input, second_float_input):
...
You can also make a custom input type by creating a class that inherits from Inputs. See inputs.py.
Metadata
Release files for formula-prompt 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| formula_prompt-0.1.0.tar.gz | 5.8 kB | Without provenance | Details for formula_prompt-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| formula_prompt-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for formula_prompt-0.1.0-py3-none-any.whl |
Total release size: 13.5 kB
Release files / formula_prompt-0.1.0.tar.gz
| Download URL | formula_prompt-0.1.0.tar.gz |
|---|---|
| Size | 5.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b53239795c520db87358f9feeaf38a46bd6269620ea536aef6b8b433f6a9ce31
|
|
BLAKE2b-256 checksum How to use checksums |
8fce09bbac89dfc5eca9ef921d2794a77326e78c2b44681f458b323f4941ca75
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.0 importlib_metadata/3.7.3 packaging/20.9 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.8
|
Release files / formula_prompt-0.1.0-py3-none-any.whl
| Download URL | formula_prompt-0.1.0-py3-none-any.whl |
|---|---|
| Size | 7.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cc24456848149c290a4e512c8d65e738ebf06ad6a1fc59676eed8643fd5acd5d
|
|
BLAKE2b-256 checksum How to use checksums |
31abe0150667ee8f3d18b35327f3766683dd91b221be61eefe1b754b7d987701
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.0 importlib_metadata/3.7.3 packaging/20.9 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.8
|
Security for formula-prompt 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.