{"id":22650656,"url":"https://github.com/data7expressions/py-expression","last_synced_at":"2025-12-14T04:46:13.497Z","repository":{"id":48519980,"uuid":"350199528","full_name":"data7expressions/py-expression","owner":"data7expressions","description":"expression, parser","archived":false,"fork":false,"pushed_at":"2023-12-28T00:48:18.000Z","size":383,"stargazers_count":6,"open_issues_count":3,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-12T03:13:32.794Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/data7expressions.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2021-03-22T03:51:51.000Z","updated_at":"2024-09-05T09:03:02.000Z","dependencies_parsed_at":"2024-01-16T12:20:02.643Z","dependency_job_id":"9013f748-ea9e-4aef-bde0-4ccf98887ceb","html_url":"https://github.com/data7expressions/py-expression","commit_stats":null,"previous_names":["expr-solver/py-expression","data7expressions/py-expression","flaviolionelrita/py-expression"],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/data7expressions%2Fpy-expression","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/data7expressions%2Fpy-expression/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/data7expressions%2Fpy-expression/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/data7expressions%2Fpy-expression/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/data7expressions","download_url":"https://codeload.github.com/data7expressions/py-expression/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248510003,"owners_count":21116130,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2024-12-09T08:36:23.810Z","updated_at":"2025-12-14T04:46:08.410Z","avatar_url":"https://github.com/data7expressions.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Py Expression\n\nPy-expression is an extensible expression evaluator and parser.\nBesides the operators, functions, variables, objects and arrays that are supported; it is possible to extend it with your own functions, operators, etc.\n\n## Features\n\n- Parse and evaluate\n  - Arithmetic operators\n  - assignment operators\n    - comparison operators\n    - Logical operators\n    - Bitwise Operators\n    - Variables\n    - Constants\n    - Functions\n    - Objects\n    - Arrays\n    - Enums\n- Simplify math operations where operands are constant\n- It allows to extend the model by adding or overwriting operators, functions and enums\n- Supports multiline expressions using the semicolon character to separate them\n- The evaluation receives the context where the variables will be read, written, and created. This context must be a dictionary or a class derived from a dictionary\n- When parsing a string that contains expression, an expression object is returned, which can be reused to evolve the expression with different contexts, in this way the performance is notably improved.\n- You can create a new expression object using expression objects and combining them with operators\n\n## Wiki\n\n[Home](https://github.com/FlavioLionelRita/py-expression/wiki)\n\n## Use\n\n### Exp\n\nExp is the main class of the library that contains the methods to parse, evaluate, get info of expression, etc . In order to use the library you need to create an instance of this class:\n\n```python\nfrom py_expression.core import Exp\nexp = Exp()\n```\n\n### Parse\n\n```python\nfrom py_expression.core import Exp\nexp = Exp()\noperand =exp.parse('a+4')\n```\n\n### Eval\n\n```python\nfrom py_expression.core import Exp\n\nexp = Exp()\noperand =exp.parse('a+4')\nresult = exp.eval(operand,{\"a\":2})\n```\n\n```python\nfrom py_expression.core import Exp\n\nexp = Exp()\noperand =exp.parse('a+4')\nresult = operand.eval({\"a\":2})\n```\n\n```python\nfrom py_expression.core import Exp\n\nexp = Exp()\nresult =exp.parse('a+4').eval({\"a\":2})\n```\n\n### Work with expressions\n\nreuse the parsed expression:\n\n```python\nfrom py_expression.core import Exp\n\nexp = Exp()\nop = exp.parse('sin(x)') \nxs=[]\nys=[] \nfor x in range(-100,100):\n    y=op.eval({\"x\":x})\n    xs.append(x)\n    ys.append(y)  \n```\n\ncreate a new expression based on two or more parsed expressions:\n\n```python\nfrom py_expression.core import Exp\n\nexp = Exp()\nop1 = exp.parse('a+1')\nop2 = exp.parse('b')\nop3 = (op1+op2)*(op1-op2) \u003e= (op1*2)\n\nresult1= op3.eval({\"a\":1,\"b\":2})\nresult2= op3.eval({\"a\":5,\"b\":9})\n\nprint(result1)\nprint(result2)\n```\n\n## Project Examples\n\n### Test Graph\n\nIn this project, the py-expression library is used to parse and evaluate expressions that a variable uses (in this case x) and the result is assigned to y.\nthen the point (x,y) is shown in a diagram.\nIn this example x takes the values from -100 to 100\n\n- [github](https://github.com/FlavioLionelRita/py-expression-test-graph)\n\n### Lib Opencv\n\nExtend the expression library by adding enums and related functions to opencv\n\n- [github](https://github.com/FlavioLionelRita/py-expression-lib-opencv)\n\n### Test Opencv\n\nIn this project, the expression library and an opencv library that adds enums and functions is used to execute multi-line expressions that transform an image\n\n- [github](https://github.com/FlavioLionelRita/py-expression-test-opencv)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdata7expressions%2Fpy-expression","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdata7expressions%2Fpy-expression","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdata7expressions%2Fpy-expression/lists"}