![pyfop](docs/logo.png)
Implements
[forward-oriented programming](https://papers.ssrn.com/sol3/papers.cfm?abstract_id=4180025)
in Python. This shares configuration arguments across multiple components
and determines their values *after* the main business logic.
![build](https://github.com/maniospas/pyfop/actions/workflows/tests.yml/badge.svg)
[![codecov](https://codecov.io/gh/maniospas/pyfop/branch/main/graph/badge.svg?token=MCsMLyteqD)](https://codecov.io/gh/maniospas/pyfop)
[![Downloads](https://static.pepy.tech/personalized-badge/pyfop?period=total&units=international_system&left_color=black&right_color=orange&left_text=Downloads)](https://pepy.tech/project/pyfop)
**Dependencies:** `makefun`<br/>
**Developer:** Emmanouil (Manios) Krasanakis<br/>
**Contant:** maniospas@hotmail.com
## Features
- Adapt arguments to usage context<br>
- Argument sharing between methods<br>
- Speed up library development<br>
- Easy adoption with decorators
## Quickstart
Enable lazy execution and automatically annotate arguments with defaults as aspects:
```python
from pyfop import lazy, autoaspects
@lazy
@autoaspects
def affine(x, scale=1, offset=0):
return x*scale + offset
```
Produce results with python code:
```python
GM = (affine(2)*affine(8))**0.5
```
Set aspect values of previous code:
```python
print(GM(scale=3)) # 12
```
## Advanced features
<details>
<summary>Internal call of lazy methods while exposing their aspects.</summary>
```python
@lazy
@autoaspects
def gm(x, y, affine=affine): # pass the method as an argument
return (affine(x)*affine(y))**0.5
GM = gm(2, 8)
print(GM(scale=3)) # 12
```
</details>
<details>
<summary>Print list of aspects.</summary>
```python
print(GM.get_input_context(scale=3))
# context:
# - scale:
# value: 3,
# priority: Priority.HIGH
# shares: 1
# - offset:
# value: 1,
# priority: Priority.INCREASED
# shares: 4
```
</details>
<details>
<summary>Aspects are shared between everything contributing to the result.</summary>
```python
@lazy
@autoaspects
def square(x, scale=1):
return scale*x*x
print(affine(2)(scale=2)) # 4
print((affine(2)+square(1))(scale=2)) # 5
```
</details>
<details>
<summary>Priority-based selection between defaults.</summary>
```python
@lazy
def logpp(x, offset=Aspect(1, Priority.INCREASED)):
import math
return math.log(x+offset)/math.log(2)
result = affine(2)+log(3)
print(result(scale=2)) # 5+2=7
```
</details>
<details>
<summary>Toggle caching.</summary>
```python
@lazy # automatically performs caching
def inc(x):
print("running")
return x+1
print(inc(2)())
# running
# 3
print(inc(2)())
# 3
print(inc(3)())
# running
# 4
```
```python
@lazy_no_cache # disables caching
def inc(x):
print("running")
return x+1
print(inc(2)())
# running
# 3
print(inc(2)())
# running
# 3
print(inc(3)())
# running
# 4
```
</details>
## Badge
Show usage of pyfop in your projects by adding the following badge to your README.md file:
```
[![pyfop](https://img.shields.io/badge/pyfop-v0.3.4-blue)](https://github.com/maniospas/pyfop)
```
This will display the following:
[![pyfop](https://img.shields.io/badge/pyfop-v0.3.4-blue)](https://github.com/maniospas/pyfop)
Raw data
{
"_id": null,
"home_page": "https://github.com/maniospas/pyfop",
"name": "pyfop",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "metaprogramming,component-based programming,software as a service",
"author": "Emmanouil Krasanakis",
"author_email": "maniospas@hotmail.com",
"download_url": "https://files.pythonhosted.org/packages/2d/e1/a25684123be2a07468bcf08f76ca82f6c32796ef0ab5b988738604f4251a/pyfop-0.3.5.tar.gz",
"platform": null,
"description": "![pyfop](docs/logo.png)\nImplements \n[forward-oriented programming](https://papers.ssrn.com/sol3/papers.cfm?abstract_id=4180025)\nin Python. This shares configuration arguments across multiple components\nand determines their values *after* the main business logic.\n\n![build](https://github.com/maniospas/pyfop/actions/workflows/tests.yml/badge.svg)\n[![codecov](https://codecov.io/gh/maniospas/pyfop/branch/main/graph/badge.svg?token=MCsMLyteqD)](https://codecov.io/gh/maniospas/pyfop)\n[![Downloads](https://static.pepy.tech/personalized-badge/pyfop?period=total&units=international_system&left_color=black&right_color=orange&left_text=Downloads)](https://pepy.tech/project/pyfop)\n\n**Dependencies:** `makefun`<br/>\n**Developer:** Emmanouil (Manios) Krasanakis<br/>\n**Contant:** maniospas@hotmail.com\n\n\n## Features\n- Adapt arguments to usage context<br>\n- Argument sharing between methods<br>\n- Speed up library development<br>\n- Easy adoption with decorators\n\n## Quickstart\nEnable lazy execution and automatically annotate arguments with defaults as aspects:\n```python\nfrom pyfop import lazy, autoaspects\n\n@lazy\n@autoaspects\ndef affine(x, scale=1, offset=0):\n return x*scale + offset\n```\nProduce results with python code:\n```python\nGM = (affine(2)*affine(8))**0.5\n```\nSet aspect values of previous code:\n```python\nprint(GM(scale=3)) # 12\n```\n\n## Advanced features\n<details>\n<summary>Internal call of lazy methods while exposing their aspects.</summary>\n\n```python\n@lazy\n@autoaspects\ndef gm(x, y, affine=affine): # pass the method as an argument\n return (affine(x)*affine(y))**0.5\n\nGM = gm(2, 8)\nprint(GM(scale=3)) # 12\n```\n\n</details>\n\n\n<details>\n<summary>Print list of aspects.</summary>\n\n```python\nprint(GM.get_input_context(scale=3))\n# context:\n#\t- scale:\n#\t\t value: 3,\n#\t\t priority: Priority.HIGH\n#\t\t shares: 1\n#\t- offset:\n#\t\t value: 1,\n#\t\t priority: Priority.INCREASED\n#\t\t shares: 4\n```\n\n</details>\n\n\n<details>\n<summary>Aspects are shared between everything contributing to the result.</summary>\n\n```python\n@lazy\n@autoaspects\ndef square(x, scale=1):\n return scale*x*x\n\nprint(affine(2)(scale=2)) # 4\nprint((affine(2)+square(1))(scale=2)) # 5\n```\n\n</details>\n\n<details>\n<summary>Priority-based selection between defaults.</summary>\n\n```python\n@lazy\ndef logpp(x, offset=Aspect(1, Priority.INCREASED)):\n import math\n return math.log(x+offset)/math.log(2)\n\nresult = affine(2)+log(3)\nprint(result(scale=2)) # 5+2=7\n```\n\n</details>\n\n\n<details>\n<summary>Toggle caching.</summary>\n\n```python\n@lazy # automatically performs caching\ndef inc(x):\n print(\"running\")\n return x+1\n\nprint(inc(2)())\n# running\n# 3 \nprint(inc(2)())\n# 3\nprint(inc(3)())\n# running\n# 4\n```\n\n```python\n@lazy_no_cache # disables caching\ndef inc(x):\n print(\"running\")\n return x+1\n\nprint(inc(2)())\n# running\n# 3 \nprint(inc(2)())\n# running\n# 3\nprint(inc(3)())\n# running\n# 4\n```\n\n</details>\n\n\n## Badge\nShow usage of pyfop in your projects by adding the following badge to your README.md file:\n```\n[![pyfop](https://img.shields.io/badge/pyfop-v0.3.4-blue)](https://github.com/maniospas/pyfop)\n```\nThis will display the following:\n\n[![pyfop](https://img.shields.io/badge/pyfop-v0.3.4-blue)](https://github.com/maniospas/pyfop)\n\n\n",
"bugtrack_url": null,
"license": "Apache 2.0",
"summary": "A forward-oriented programming paradigm for Python.",
"version": "0.3.5",
"split_keywords": [
"metaprogramming",
"component-based programming",
"software as a service"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "daea26033545eac67d92ddb6bd73c486597fd86bd5260f10152acc6a3776e693",
"md5": "74f08aee693829f1ac2c1365e9eb943f",
"sha256": "17de4ce501555dab04e1cdc971d2faae8d6591ae65754ae34e11433859557c3a"
},
"downloads": -1,
"filename": "pyfop-0.3.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "74f08aee693829f1ac2c1365e9eb943f",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 16763,
"upload_time": "2023-01-16T13:38:52",
"upload_time_iso_8601": "2023-01-16T13:38:52.191286Z",
"url": "https://files.pythonhosted.org/packages/da/ea/26033545eac67d92ddb6bd73c486597fd86bd5260f10152acc6a3776e693/pyfop-0.3.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "2de1a25684123be2a07468bcf08f76ca82f6c32796ef0ab5b988738604f4251a",
"md5": "ff092818e08e1a5eaabb47b820d28327",
"sha256": "59f781177284fe2a9050876cbf6f8a087d5e1fdd37340642cacf13f41d7f2098"
},
"downloads": -1,
"filename": "pyfop-0.3.5.tar.gz",
"has_sig": false,
"md5_digest": "ff092818e08e1a5eaabb47b820d28327",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 15401,
"upload_time": "2023-01-16T13:38:56",
"upload_time_iso_8601": "2023-01-16T13:38:56.267144Z",
"url": "https://files.pythonhosted.org/packages/2d/e1/a25684123be2a07468bcf08f76ca82f6c32796ef0ab5b988738604f4251a/pyfop-0.3.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-01-16 13:38:56",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "maniospas",
"github_project": "pyfop",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "pyfop"
}