{"id":15975460,"url":"https://github.com/alexmojaki/datafunctions","last_synced_at":"2025-04-04T17:13:36.760Z","repository":{"id":66101876,"uuid":"261007023","full_name":"alexmojaki/datafunctions","owner":"alexmojaki","description":"Automatic (de)serialization of arguments and return values for Python functions","archived":false,"fork":false,"pushed_at":"2020-06-06T20:52:34.000Z","size":20,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-01T11:53:19.869Z","etag":null,"topics":["annotations","dataclass","decorator","marshmallow","python","python-functions","serialization"],"latest_commit_sha":null,"homepage":null,"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/alexmojaki.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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}},"created_at":"2020-05-03T19:39:09.000Z","updated_at":"2024-11-18T19:47:52.000Z","dependencies_parsed_at":null,"dependency_job_id":"5eb49ade-e270-4790-9d23-b3cfe30bf06a","html_url":"https://github.com/alexmojaki/datafunctions","commit_stats":{"total_commits":15,"total_committers":1,"mean_commits":15.0,"dds":0.0,"last_synced_commit":"54274cce6fbe96f31dacb6fba44ea072b52c75fe"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexmojaki%2Fdatafunctions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexmojaki%2Fdatafunctions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexmojaki%2Fdatafunctions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexmojaki%2Fdatafunctions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexmojaki","download_url":"https://codeload.github.com/alexmojaki/datafunctions/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247217221,"owners_count":20903009,"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":["annotations","dataclass","decorator","marshmallow","python","python-functions","serialization"],"created_at":"2024-10-07T22:01:53.665Z","updated_at":"2025-04-04T17:13:36.736Z","avatar_url":"https://github.com/alexmojaki.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# datafunctions\n\n[![Build Status](https://travis-ci.org/alexmojaki/datafunctions.svg?branch=master)](https://travis-ci.org/alexmojaki/datafunctions) [![Coverage Status](https://coveralls.io/repos/github/alexmojaki/datafunctions/badge.svg?branch=master)](https://coveralls.io/github/alexmojaki/datafunctions?branch=master) [![Supports Python versions 3.7+](https://img.shields.io/pypi/pyversions/datafunctions.svg)](https://pypi.python.org/pypi/datafunctions)\n\nAutomatic (de)serialization of arguments and return values for Python functions.\n\n    pip install datafunctions\n\n`@datafunction` is a decorator which automatically deserializes incoming arguments of the decorated function and\nserializes the return value. For example:\n\n```python\nfrom datetime import datetime\nfrom datafunctions import datafunction\n\n@datafunction\ndef next_year(dt: datetime) -\u003e datetime:\n    return dt.replace(year=dt.year + 1)\n\nassert next_year(\"2019-01-02T00:00:00\") == \"2020-01-02T00:00:00\"\n```\n\n`@datafunction` automatically converts the string argument to a datetime object, and then\nconverts the returned datetime back to a string.\n\nThis is useful for calling functions over a remote connection or from a different language - see [instant_api](https://github.com/alexmojaki/instant_api) and [instant_client](https://github.com/alexmojaki/instant_client) for example.\n\nMore generally, the arguments and return value as seen from the outside the function\nare basic JSON serializable objects - strings, dicts, etc.\nThey are converted to and from the correct types (as indicated by type annotations)\nby [marshmallow](https://marshmallow.readthedocs.io/). Common Python types as well as dataclasses (which may be nested)\nare supported. For example:\n\n```python\nfrom dataclasses import dataclass\nfrom datafunctions import datafunction\n\n@dataclass\nclass Point:\n    x: int\n    y: int\n\n@datafunction\ndef translate(p: Point, dx: int, dy: int) -\u003e Point:\n    return Point(p.x + dx, p.y + dy)\n\nassert translate({\"x\": 1, \"y\": 2}, 3, 4) == {\"x\": 4, \"y\": 6}\n```\n\nTo decorate a method, pass `is_method=True`, e.g:\n\n```python\nclass MyClass:\n    @datafunction(is_method=True)\n    def method(self, x: int) -\u003e int:\n        ...\n```\n\nAll parameters and the return value must have a type annotation,\nexcept for the first argument when `is_method=True`.\nVariadic parameters (e.g. `*args` or `**kwargs`) and positional-only parameters (before `/`)\nare not allowed.\n\nIf there is an exception deserializing or binding the arguments an `ArgumentError`\nwill be raised with the underlying exception attached to `__cause__`.\nSimilarly a `ReturnError` may be raised when trying to serialize the return value.\n\nFor more manual control, use the methods:\n\n- `load_arguments`\n- `dump_arguments`\n- `load_result`\n- `dump_result`\n\nUnder the hood, the type annotations are gathered into a [dataclass](https://docs.python.org/3/library/dataclasses.html) which is then\nconverted into a [marshmallow](https://marshmallow.readthedocs.io/en/stable/) schema\nusing [marshmallow_dataclass](https://github.com/lovasoa/marshmallow_dataclass).\nmarshmallow handles the (de)serialization.\n\nInstances of this class have attributes `params_schemas` and `return_schemas`,\neach of which have the following attributes:\n\n- `dataclass`\n- `schema_class`: the marshmallow schema class\n- `schema_instance`: a no-args instance of schema_class\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexmojaki%2Fdatafunctions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexmojaki%2Fdatafunctions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexmojaki%2Fdatafunctions/lists"}