transfunctions


Nametransfunctions JSON
Version 0.0.1 PyPI version JSON
download
home_pageNone
SummarySay NO to Python fragmentation on sync and async
upload_time2025-07-15 09:27:57
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseNone
keywords async sync to async async to sync
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # transfunctions

[![Downloads](https://static.pepy.tech/badge/transfunctions/month)](https://pepy.tech/project/transfunctions)
[![Downloads](https://static.pepy.tech/badge/transfunctions)](https://pepy.tech/project/transfunctions)
[![Coverage Status](https://coveralls.io/repos/github/pomponchik/transfunctions/badge.svg?branch=main)](https://coveralls.io/github/pomponchik/transfunctions?branch=develop)
[![Lines of code](https://sloc.xyz/github/pomponchik/transfunctions/?category=code)](https://github.com/boyter/scc/)
[![Hits-of-Code](https://hitsofcode.com/github/pomponchik/transfunctions?branch=main)](https://hitsofcode.com/github/pomponchik/transfunctions/view?branch=main)
[![Test-Package](https://github.com/pomponchik/transfunctions/actions/workflows/tests_and_coverage.yml/badge.svg)](https://github.com/pomponchik/transfunctions/actions/workflows/tests_and_coverage.yml)
[![Python versions](https://img.shields.io/pypi/pyversions/transfunctions.svg)](https://pypi.python.org/pypi/transfunctions)
[![PyPI version](https://badge.fury.io/py/transfunctions.svg)](https://badge.fury.io/py/transfunctions)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)

This library is designed to solve one of the most important problems in python programming - dividing all written code into 2 camps: sync and async. We get rid of code duplication by using templates.


## Table of contents

- [**Quick start**](#quick-start)
- [**The problem**](#the-problem)


## Quick start

Install it:

```bash
pip install transfunctions
```

And use:

```python
from asyncio import run
from transfunctions import (
    transfunction,
    sync_context,
    async_context,
    generator_context,
)

@transfunction
def template():
    print('so, ', end='')
    with sync_context:
        print("it's just usual function!")
    with async_context:
        print("it's an async function!")
    with generator_context:
        print("it's a generator function!")
        yield

function = template.get_usual_function()
function()
#> so, it's just usual function!

async_function = template.get_async_function()
run(async_function())
#> so, it's an async function!

generator_function = template.get_generator_function()
list(generator_function())
#> so, it's a generator function!
```

As you can see, in this case, 3 different functions were created based on the template, including both common parts and unique ones for a specific type of function.

You can also quickly try out this and other packages without having to install using [instld](https://github.com/pomponchik/instld).


## The problem

Since the `asyncio` module appeared in Python more than 10 years ago, many well-known libraries have received their asynchronous alternates. A lot of the code in the Python ecosystem has been [duplicated](https://en.wikipedia.org/wiki/Don%27t_repeat_yourself), and you probably know many such examples.

The reason for this problem is that the Python community has chosen a way to implement asynchrony expressed through syntax. There are new keywords in the language, such as `async` and `await`. Their use makes the code so-called "[multicolored](https://journal.stuffwithstuff.com/2015/02/01/what-color-is-your-function/)": all the functions in it can be red or blue, and depending on the color, the rules for calling them are different. You can only call blue functions from red ones, but not vice versa.

I must say that implementing asynchronous calls using a special syntax is not the only solution. There are languages like Go where runtime can independently determine "under the hood" where a function should be asynchronous and where not, and choose the correct way to call it. A programmer does not need to manually "colorize" their functions there. Personally, I think that choosing a different path is the mistake of the Python community, but that's not what we're discussing here.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "transfunctions",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "async, sync to async, async to sync",
    "author": null,
    "author_email": "Evgeniy Blinov <zheni-b@yandex.ru>",
    "download_url": "https://files.pythonhosted.org/packages/c4/b7/3971ae3eb2519c9eeebed1172d055dee221c128b41ab51db1bfe5ecf2c22/transfunctions-0.0.1.tar.gz",
    "platform": null,
    "description": "# transfunctions\n\n[![Downloads](https://static.pepy.tech/badge/transfunctions/month)](https://pepy.tech/project/transfunctions)\n[![Downloads](https://static.pepy.tech/badge/transfunctions)](https://pepy.tech/project/transfunctions)\n[![Coverage Status](https://coveralls.io/repos/github/pomponchik/transfunctions/badge.svg?branch=main)](https://coveralls.io/github/pomponchik/transfunctions?branch=develop)\n[![Lines of code](https://sloc.xyz/github/pomponchik/transfunctions/?category=code)](https://github.com/boyter/scc/)\n[![Hits-of-Code](https://hitsofcode.com/github/pomponchik/transfunctions?branch=main)](https://hitsofcode.com/github/pomponchik/transfunctions/view?branch=main)\n[![Test-Package](https://github.com/pomponchik/transfunctions/actions/workflows/tests_and_coverage.yml/badge.svg)](https://github.com/pomponchik/transfunctions/actions/workflows/tests_and_coverage.yml)\n[![Python versions](https://img.shields.io/pypi/pyversions/transfunctions.svg)](https://pypi.python.org/pypi/transfunctions)\n[![PyPI version](https://badge.fury.io/py/transfunctions.svg)](https://badge.fury.io/py/transfunctions)\n[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)\n\nThis library is designed to solve one of the most important problems in python programming - dividing all written code into 2 camps: sync and async. We get rid of code duplication by using templates.\n\n\n## Table of contents\n\n- [**Quick start**](#quick-start)\n- [**The problem**](#the-problem)\n\n\n## Quick start\n\nInstall it:\n\n```bash\npip install transfunctions\n```\n\nAnd use:\n\n```python\nfrom asyncio import run\nfrom transfunctions import (\n    transfunction,\n    sync_context,\n    async_context,\n    generator_context,\n)\n\n@transfunction\ndef template():\n    print('so, ', end='')\n    with sync_context:\n        print(\"it's just usual function!\")\n    with async_context:\n        print(\"it's an async function!\")\n    with generator_context:\n        print(\"it's a generator function!\")\n        yield\n\nfunction = template.get_usual_function()\nfunction()\n#> so, it's just usual function!\n\nasync_function = template.get_async_function()\nrun(async_function())\n#> so, it's an async function!\n\ngenerator_function = template.get_generator_function()\nlist(generator_function())\n#> so, it's a generator function!\n```\n\nAs you can see, in this case, 3 different functions were created based on the template, including both common parts and unique ones for a specific type of function.\n\nYou can also quickly try out this and other packages without having to install using [instld](https://github.com/pomponchik/instld).\n\n\n## The problem\n\nSince the `asyncio` module appeared in Python more than 10 years ago, many well-known libraries have received their asynchronous alternates. A lot of the code in the Python ecosystem has been [duplicated](https://en.wikipedia.org/wiki/Don%27t_repeat_yourself), and you probably know many such examples.\n\nThe reason for this problem is that the Python community has chosen a way to implement asynchrony expressed through syntax. There are new keywords in the language, such as `async` and `await`. Their use makes the code so-called \"[multicolored](https://journal.stuffwithstuff.com/2015/02/01/what-color-is-your-function/)\": all the functions in it can be red or blue, and depending on the color, the rules for calling them are different. You can only call blue functions from red ones, but not vice versa.\n\nI must say that implementing asynchronous calls using a special syntax is not the only solution. There are languages like Go where runtime can independently determine \"under the hood\" where a function should be asynchronous and where not, and choose the correct way to call it. A programmer does not need to manually \"colorize\" their functions there. Personally, I think that choosing a different path is the mistake of the Python community, but that's not what we're discussing here.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Say NO to Python fragmentation on sync and async",
    "version": "0.0.1",
    "project_urls": {
        "Source": "https://github.com/pomponchik/transfunctions",
        "Tracker": "https://github.com/pomponchik/transfunctions/issues"
    },
    "split_keywords": [
        "async",
        " sync to async",
        " async to sync"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "8a8309db16e2194dba11b5f5aab7b411990bc858a75ccd9f081453a6478dc994",
                "md5": "a47e68f258bd9de6a0144f7b1ef922aa",
                "sha256": "6f052d7cb6284d247b0d767fcdd9e10bd4771293180a958807efea2a788ab647"
            },
            "downloads": -1,
            "filename": "transfunctions-0.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a47e68f258bd9de6a0144f7b1ef922aa",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 7519,
            "upload_time": "2025-07-15T09:27:56",
            "upload_time_iso_8601": "2025-07-15T09:27:56.044179Z",
            "url": "https://files.pythonhosted.org/packages/8a/83/09db16e2194dba11b5f5aab7b411990bc858a75ccd9f081453a6478dc994/transfunctions-0.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "c4b73971ae3eb2519c9eeebed1172d055dee221c128b41ab51db1bfe5ecf2c22",
                "md5": "980d6419b03e533e8214ab2587c71edf",
                "sha256": "dbad1967b2097e68bf9610bb02783e09fead3897ce5e998e6d9503a5ef421c5b"
            },
            "downloads": -1,
            "filename": "transfunctions-0.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "980d6419b03e533e8214ab2587c71edf",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 8106,
            "upload_time": "2025-07-15T09:27:57",
            "upload_time_iso_8601": "2025-07-15T09:27:57.413823Z",
            "url": "https://files.pythonhosted.org/packages/c4/b7/3971ae3eb2519c9eeebed1172d055dee221c128b41ab51db1bfe5ecf2c22/transfunctions-0.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-15 09:27:57",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "pomponchik",
    "github_project": "transfunctions",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "transfunctions"
}
        
Elapsed time: 1.48785s