{"id":51417910,"url":"https://github.com/stur86/parsimathious","last_synced_at":"2026-07-04T21:30:55.869Z","repository":{"id":365849523,"uuid":"1223526948","full_name":"stur86/parsimathious","owner":"stur86","description":"A simple mathematical expression parser","archived":false,"fork":false,"pushed_at":"2026-06-19T07:52:55.000Z","size":108,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-06-19T08:14:08.412Z","etag":null,"topics":["math","parser","parsimonious","parsing-library","utility"],"latest_commit_sha":null,"homepage":"","language":"Python","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/stur86.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-04-28T12:08:41.000Z","updated_at":"2026-06-19T07:52:38.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/stur86/parsimathious","commit_stats":null,"previous_names":["stur86/parsimathious"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/stur86/parsimathious","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stur86%2Fparsimathious","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stur86%2Fparsimathious/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stur86%2Fparsimathious/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stur86%2Fparsimathious/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stur86","download_url":"https://codeload.github.com/stur86/parsimathious/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stur86%2Fparsimathious/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35136712,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-04T02:00:05.987Z","response_time":113,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["math","parser","parsimonious","parsing-library","utility"],"created_at":"2026-07-04T21:30:55.789Z","updated_at":"2026-07-04T21:30:55.855Z","avatar_url":"https://github.com/stur86.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# parsimathious\n\n[![PyPI](https://img.shields.io/pypi/v/parsimathious)](https://pypi.org/project/parsimathious/)\n[![Python](https://img.shields.io/pypi/pyversions/parsimathious)](https://pypi.org/project/parsimathious/)\n[![Tests](https://github.com/stur86/parsimathious/actions/workflows/test.yml/badge.svg)](https://github.com/stur86/parsimathious/actions/workflows/test.yml)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n`parsimathious` is a simple mathematical expression parser implemented with [`parsimonious`](https://github.com/erikrose/parsimonious). It supports basic arithmetic operations, parentheses, unary functions, constants, variables, and complex numbers.\n\n## Installation\n\nYou can install `parsimathious` using pip:\n\n```bash\npip install parsimathious\n```\n\n## Usage\n\nImport the `ExpressionParser` and create an instance:\n\n```python\nfrom parsimathious import ExpressionParser\n\nparser = ExpressionParser()\n```\n\nThen you can parse and evaluate expressions:\n\n```python\nresult = parser(\"sin(pi / 2) + 1\")\nprint(result)  # Output: 2.0\n```\n\n## Supported functions and constants\n\n\nOn top of basic arithmetic operations, `parsimathious` supports the following unary functions and constants by default:\n\n| Name     | Python Implementation           | Description                       |\n|----------|--------------------------------|------------------------------------|\n| `sin`    | math.sin                       | Sine                               |\n| `cos`    | math.cos                       | Cosine                             |\n| `tan`    | math.tan                       | Tangent                            |\n| `log`    | math.log                       | Natural logarithm (base e)         |\n| `sqrt`   | math.sqrt                      | Square root                        |\n| `exp`    | math.exp                       | Exponential (e^x)                  |\n| `log10`  | math.log10                     | Logarithm base 10                  |\n| `abs`    | abs                            | Absolute value                     |\n| `floor`  | math.floor                     | Floor (round down)                 |\n| `ceil`   | math.ceil                      | Ceiling (round up)                 |\n| `round`  | round                          | Round to nearest integer           |\n| `sinh`   | math.sinh                      | Hyperbolic sine                    |\n| `cosh`   | math.cosh                      | Hyperbolic cosine                  |\n| `tanh`   | math.tanh                      | Hyperbolic tangent                 |\n| `asin`   | math.asin                      | Arc sine                           |\n| `acos`   | math.acos                      | Arc cosine                         |\n| `atan`   | math.atan                      | Arc tangent                        |\n| `asinh`  | math.asinh                     | Inverse hyperbolic sine            |\n| `acosh`  | math.acosh                     | Inverse hyperbolic cosine          |\n| `atanh`  | math.atanh                     | Inverse hyperbolic tangent         |\n| `sec`    | lambda x: 1 / math.cos(x)      | Secant                             |\n| `csc`    | lambda x: 1 / math.sin(x)      | Cosecant                           |\n| `cot`    | lambda x: 1 / math.tan(x)      | Cotangent                          |\n\n### Constants\n\n| Name | Value                | Description                |\n|------|----------------------|----------------------------|\n| `pi` | math.pi              | The mathematical constant π |\n| `e`  | math.e               | The mathematical constant e |\n| `i`  | 1j                   | The imaginary unit         |\n\n## Custom Unary Functions\n\nIt's also possible to support custom unary functions by passing a dictionary of function names to their implementations when creating the `ExpressionParser`:\n\n```python\nimport math\nfrom parsimathious import ExpressionParser, UnaryFunctionMap\n\ncustom_functions: UnaryFunctionMap = {\n    \"log2\": math.log2,  # Logarithm base 2\n    \"cube\": lambda x: x ** 3,  # Cube function\n}\n\nparser = ExpressionParser(unary_functions=custom_functions)\nresult = parser(\"log2(8) + cube(3)\")\nprint(result)  # Output: 30.0\n```\n\n## Custom Constants\n\nCustom constants can be passed via a dictionary of names to values when creating the `ExpressionParser`. This **replaces** the default constants (`pi`, `e`) rather than extending them, so include them again if you still need them:\n\n```python\nimport math\nfrom parsimathious import ExpressionParser, ConstantMap\n\ncustom_constants: ConstantMap = {\n    \"pi\": math.pi,\n    \"tau\": 2 * math.pi,\n}\n\nparser = ExpressionParser(constants=custom_constants)\nresult = parser(\"tau / pi\")\nprint(result)  # Output: 2.0\n```\n\nConstant names cannot overlap with variable names (see below), and `i` is reserved for the imaginary unit and cannot be used as a constant name.\n\n## Variables\n\nUnlike constants, variables don't have a fixed value: their names are declared when creating the `ExpressionParser`, and their values are supplied at evaluation time, by passing a dictionary of names to values to the parser call (or to `eval_ast`):\n\n```python\nfrom parsimathious import ExpressionParser\n\nparser = ExpressionParser(variable_names=[\"x\", \"y\"])\nresult = parser(\"x + y * 2\", variables={\"x\": 1.0, \"y\": 3.0})\nprint(result)  # Output: 7.0\n```\n\nEach call only uses the variable values passed to it; if an expression references a declared variable but no value is provided for it, a `ValueError` is raised. As with constants, `i` is reserved for the imaginary unit and cannot be used as a variable name, and variable names cannot overlap with constant names.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstur86%2Fparsimathious","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstur86%2Fparsimathious","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstur86%2Fparsimathious/lists"}