lambdser


Namelambdser JSON
Version 0.1.2 PyPI version JSON
download
home_pagehttps://github.com/cloasdata/lambdser
Summaryfast lambda expression serializer
upload_time2023-08-26 20:15:49
maintainer
docs_urlNone
authorSimon Bauer
requires_python
licenseMIT
keywords dill lambda serializer pickle
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # lambdser

A lambda expression serializer for python. Can be used to make pickle eat lambdas with closures.

A typical use case is serializing lambdas for multiprocessing. Using lambdser in front, let multiprocessing eat
the lambda expression.

## Install

    pip install lambdser

or install it from github
    
    pip install git+https://github.com/cloasdata/lambdser.git

or just clone it

## todo

I did not find a way to register lambdser es pickler in the pickle module. It would be really useful
if somebody can help me. However, one can use the LambdserPickler class 
to overwrite the default behaviour of pickle.Pickler (?) or use LamdserPickler as the one pickler.

I also did not test for particular edge cases. But feel free to contribute such tests.


## usage

### Example 1: module namespace

using it in module namespace.

``` python
    import pickle
    import lambdser
    
    
    two = "2"
    expression = lambda x: "number" + x + two
    
    result1 = expression("4")
    ser = lambdser.dumps(expression)
    # now pickle can dump!
    s = pickle.dumps(ser)
    ser = pickle.loads(s)
    
    expression = lambdser.loads(ser)
    result2 = expression("4")
    assert result1 == result2
```

### Example 2: Using closure

Make a proxy of what you want to spawn in a separate process.

``` python
    import lambdser
    import multiprocessing as mp
    
    
    def make_proxy(para, *funcs):
        # make proxy for the mp
        ser_list = []
        for f in funcs:
            ser_list.append(lambdser.dumps(f))
        return para, ser_list
    
    
    def processor(*ser):
        # unzip the proxy and to the work
        para, funcs = ser
        funcs = [lambdser.loads(ser) for ser in funcs]
        res = None
        for f in funcs:
            res = f(para)
        print(res)
        return res
    
    
    def do_stuff():
        two = "2"
        ser = make_proxy("4", lambda x: x + two)
        mp.Process(target=processor, args=ser).start()

    do_stuff()
```

## performance

it is around 100 times faster than dill. This was one reason to develop this package. 
    
    py .\test\profiling.py

    Results dumps
    lambdser: 0.012459
    dill:     1.485589
    times:    119.236291

Copyright © 2022 Simon Bauer

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/cloasdata/lambdser",
    "name": "lambdser",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "dill,lambda,serializer,pickle",
    "author": "Simon Bauer",
    "author_email": "code@seimenadventure.de",
    "download_url": "https://files.pythonhosted.org/packages/99/80/565be71118a78c38251f04cd8942e44acb8b8795172ce4e07c9546f92e84/lambdser-0.1.2.tar.gz",
    "platform": null,
    "description": "# lambdser\r\n\r\nA lambda expression serializer for python. Can be used to make pickle eat lambdas with closures.\r\n\r\nA typical use case is serializing lambdas for multiprocessing. Using lambdser in front, let multiprocessing eat\r\nthe lambda expression.\r\n\r\n## Install\r\n\r\n    pip install lambdser\r\n\r\nor install it from github\r\n    \r\n    pip install git+https://github.com/cloasdata/lambdser.git\r\n\r\nor just clone it\r\n\r\n## todo\r\n\r\nI did not find a way to register lambdser es pickler in the pickle module. It would be really useful\r\nif somebody can help me. However, one can use the LambdserPickler class \r\nto overwrite the default behaviour of pickle.Pickler (?) or use LamdserPickler as the one pickler.\r\n\r\nI also did not test for particular edge cases. But feel free to contribute such tests.\r\n\r\n\r\n## usage\r\n\r\n### Example 1: module namespace\r\n\r\nusing it in module namespace.\r\n\r\n``` python\r\n    import pickle\r\n    import lambdser\r\n    \r\n    \r\n    two = \"2\"\r\n    expression = lambda x: \"number\" + x + two\r\n    \r\n    result1 = expression(\"4\")\r\n    ser = lambdser.dumps(expression)\r\n    # now pickle can dump!\r\n    s = pickle.dumps(ser)\r\n    ser = pickle.loads(s)\r\n    \r\n    expression = lambdser.loads(ser)\r\n    result2 = expression(\"4\")\r\n    assert result1 == result2\r\n```\r\n\r\n### Example 2: Using closure\r\n\r\nMake a proxy of what you want to spawn in a separate process.\r\n\r\n``` python\r\n    import lambdser\r\n    import multiprocessing as mp\r\n    \r\n    \r\n    def make_proxy(para, *funcs):\r\n        # make proxy for the mp\r\n        ser_list = []\r\n        for f in funcs:\r\n            ser_list.append(lambdser.dumps(f))\r\n        return para, ser_list\r\n    \r\n    \r\n    def processor(*ser):\r\n        # unzip the proxy and to the work\r\n        para, funcs = ser\r\n        funcs = [lambdser.loads(ser) for ser in funcs]\r\n        res = None\r\n        for f in funcs:\r\n            res = f(para)\r\n        print(res)\r\n        return res\r\n    \r\n    \r\n    def do_stuff():\r\n        two = \"2\"\r\n        ser = make_proxy(\"4\", lambda x: x + two)\r\n        mp.Process(target=processor, args=ser).start()\r\n\r\n    do_stuff()\r\n```\r\n\r\n## performance\r\n\r\nit is around 100 times faster than dill. This was one reason to develop this package. \r\n    \r\n    py .\\test\\profiling.py\r\n\r\n    Results dumps\r\n    lambdser: 0.012459\r\n    dill:     1.485589\r\n    times:    119.236291\r\n\r\nCopyright \u00a9 2022 Simon Bauer\r\n\r\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \u201cSoftware\u201d), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\r\n\r\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\r\n\r\nTHE SOFTWARE IS PROVIDED \u201cAS IS\u201d, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "fast lambda expression serializer",
    "version": "0.1.2",
    "project_urls": {
        "Homepage": "https://github.com/cloasdata/lambdser"
    },
    "split_keywords": [
        "dill",
        "lambda",
        "serializer",
        "pickle"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ee670a8a200e86c38b14f132b3b8d37b4681dbe39eb25656ff9ed52cbef2f9db",
                "md5": "5c5d85e4774170bdb44e5a04d883f93d",
                "sha256": "c1a2364ea276de938720c9f978e94beb526baf90a34cef7dd3d0e8a1ee1701fe"
            },
            "downloads": -1,
            "filename": "lambdser-0.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5c5d85e4774170bdb44e5a04d883f93d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 5157,
            "upload_time": "2023-08-26T20:15:48",
            "upload_time_iso_8601": "2023-08-26T20:15:48.486141Z",
            "url": "https://files.pythonhosted.org/packages/ee/67/0a8a200e86c38b14f132b3b8d37b4681dbe39eb25656ff9ed52cbef2f9db/lambdser-0.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9980565be71118a78c38251f04cd8942e44acb8b8795172ce4e07c9546f92e84",
                "md5": "ee666382bdd08ee0834b96e3bfae8050",
                "sha256": "29b0ecf64a25173ad01da8a1a52f61a67221c36059b672029b4f6453c7f19512"
            },
            "downloads": -1,
            "filename": "lambdser-0.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "ee666382bdd08ee0834b96e3bfae8050",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 5486,
            "upload_time": "2023-08-26T20:15:49",
            "upload_time_iso_8601": "2023-08-26T20:15:49.905719Z",
            "url": "https://files.pythonhosted.org/packages/99/80/565be71118a78c38251f04cd8942e44acb8b8795172ce4e07c9546f92e84/lambdser-0.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-26 20:15:49",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "cloasdata",
    "github_project": "lambdser",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "lambdser"
}
        
Elapsed time: 0.15095s