Skip to main content

A formula parser for python.

Copyright (C) 2017 Lars van de Kerkhof

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

what it does

Parses simple arythmetic formula’s containing variables. Can then be used to compute values resolving the variables from a context object.

>>> from argparse import Namespace as KeyedObject
>>> from formulaparser import Formula
>>>
>>> context = KeyedObject()
>>> context.four = 4
>>> context.three = 3
>>> deepercontext = KeyedObject()
>>> deepercontext.ten = 10
>>> deepercontext.twelve = 12
>>> context.nextlevel = deepercontext
>>>
>>> Formula("((1 + 2 + 3) + 4 + (3 + 7)) + 5").calculate_value()
25
>>> Formula("4!").calculate_value()
24
>>> Formula("3.287 / 6").calculate_value()
0.5478333333333333
>>> Formula("2 ^ 8").calculate_value()
256
>>> Formula("4 - (-4)").calculate_value()
8
>>> Formula("(4 * 6) - 8 + 7 - 4 + 3").calculate_value()
22
>>> Formula("((1 + four + 3) + nextlevel.ten + (3 + 7)) + 5").calculate_value(context)
33
>>> Formula("((four!) - 6) / nextlevel.twelve").calculate_value(context)
1.5
>>> Formula("2 ^ three").calculate_value(context)
8
>>> Formula("nextlevel.twelve - (-four)").calculate_value(context)
16
>>> Formula("(four * 6) - nextlevel.ten + 7 - 4 + 3").calculate_value(context)
20

Metadata

Release files for formulaparser 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for formulaparser 0.0.1
File Size Uploaded Provenance
formulaparser-0.0.1.tar.gz 15.9 kB Without provenance Details

Release files / formulaparser-0.0.1.tar.gz

Download URL formulaparser-0.0.1.tar.gz
Size 15.9 kB
Tags Source
SHA-256 checksum
How to use checksums
090c9cbc3a91d914b2be59b5cd29e80f21ca170ff8272fc6da9c10af2abf5855
BLAKE2b-256 checksum
How to use checksums
ff4228b9be2ee5ed92fa2f6bb5169cc16ad21f929371410c038b89c8508b75a7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for formulaparser 0.0.1

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.

Release history Release notifications | RSS feed

This release

0.0.1 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page