devpytools


Namedevpytools JSON
Version 0.1.0.dev7 PyPI version JSON
download
home_pagehttps://github.com/glowlex/devpytools
SummaryVarious dev tools.
upload_time2023-11-11 14:50:20
maintainer
docs_urlNone
authorglowlex
requires_python
licenseMIT
keywords tools cache dev
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # devpytools
Tools for development.

## Installation
```
$ pip install devpytools
```

## Usage
### Cacher
Get and use default inmemory cacher
```python
from devpytools import getCacher
c = getCacher()
@c.cache()
def a(b):
    ...
```

Create the cacher that saves a pickled data on disk and can be used between runs
```python
from devpytools import Cacher
c = Cacher(name='dev', tmpDirPath='./tmp')
```

Get previously configured cacher in other file and use
```python
from devpytools import getCacher
c = getCacher("dev")
@c.cache
def a(b):
    ...
```

Example
```python
from devpytools import Cacher
from devpytools.cacher import extensions
IS_DEV = os.getenv("IS_DEV", "") == "true"

devCacher = Cacher(
    name="dev",
    tmpDirPath="./tmp",
    isEnable=IS_DEV,  # work only if run in dev environment
    isExpired=extensions.expireAfterHours(1),  # recache if cached data older than 1 hour
    isSavable=lambda result: bool(result),  # only cache positive function call results
)

@devCacher.cache
def a(b):
    ...

# works with the same params as devCacher but saves caches to ./tmp1 folder
@devCacher.cache(tmpDirPath="./tmp1")
def a1(b):
    ...

# currently disable cache for that func
@devCacher.cache(isEnable=False)
def a2(b):
    ...

# cache only those calls that return more than 0 elements
@devCacher.cache(isSavable=lambda result: result['count'] > 0)
def a3(b):
    ...

# use only a and b arguments to determine unique key of the function call
@devCacher.cache(uniqueKey=lambda args: args['a'] + args['b'])
def a4(a: str, b: str, c: str):
    ...
```
```python
c = getCacher()
# to determine the uniqueness of a function call use only a and b arguments
@c.cache(uniqueKey=("a", "b"))
def a(a, b, c):
    ...
```

### Other
- replaceFunc
```python
from devpytools import replaceFunc
IS_DEV = os.getenv("IS_DEV", "") == "true"

def devFunc():
    # predefined results for development
    ...
# replace only if IS_DEV is True
@replaceFunc(devFunc, isEnabled=IS_DEV)
def prodFunc():
    # time consuming function
    ...
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/glowlex/devpytools",
    "name": "devpytools",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "tools,cache,dev",
    "author": "glowlex",
    "author_email": "antonioavocado777@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/88/e9/2b3a9e8d1a290be82e1364ff12560f975ba0e1e97df17e394f99178b5756/devpytools-0.1.0.dev7.tar.gz",
    "platform": null,
    "description": "# devpytools\r\nTools for development.\r\n\r\n## Installation\r\n```\r\n$ pip install devpytools\r\n```\r\n\r\n## Usage\r\n### Cacher\r\nGet and use default inmemory cacher\r\n```python\r\nfrom devpytools import getCacher\r\nc = getCacher()\r\n@c.cache()\r\ndef a(b):\r\n    ...\r\n```\r\n\r\nCreate the cacher that saves a pickled data on disk and can be used between runs\r\n```python\r\nfrom devpytools import Cacher\r\nc = Cacher(name='dev', tmpDirPath='./tmp')\r\n```\r\n\r\nGet previously configured cacher in other file and use\r\n```python\r\nfrom devpytools import getCacher\r\nc = getCacher(\"dev\")\r\n@c.cache\r\ndef a(b):\r\n    ...\r\n```\r\n\r\nExample\r\n```python\r\nfrom devpytools import Cacher\r\nfrom devpytools.cacher import extensions\r\nIS_DEV = os.getenv(\"IS_DEV\", \"\") == \"true\"\r\n\r\ndevCacher = Cacher(\r\n    name=\"dev\",\r\n    tmpDirPath=\"./tmp\",\r\n    isEnable=IS_DEV,  # work only if run in dev environment\r\n    isExpired=extensions.expireAfterHours(1),  # recache if cached data older than 1 hour\r\n    isSavable=lambda result: bool(result),  # only cache positive function call results\r\n)\r\n\r\n@devCacher.cache\r\ndef a(b):\r\n    ...\r\n\r\n# works with the same params as devCacher but saves caches to ./tmp1 folder\r\n@devCacher.cache(tmpDirPath=\"./tmp1\")\r\ndef a1(b):\r\n    ...\r\n\r\n# currently disable cache for that func\r\n@devCacher.cache(isEnable=False)\r\ndef a2(b):\r\n    ...\r\n\r\n# cache only those calls that return more than 0 elements\r\n@devCacher.cache(isSavable=lambda result: result['count'] > 0)\r\ndef a3(b):\r\n    ...\r\n\r\n# use only a and b arguments to determine unique key of the function call\r\n@devCacher.cache(uniqueKey=lambda args: args['a'] + args['b'])\r\ndef a4(a: str, b: str, c: str):\r\n    ...\r\n```\r\n```python\r\nc = getCacher()\r\n# to determine the uniqueness of a function call use only a and b arguments\r\n@c.cache(uniqueKey=(\"a\", \"b\"))\r\ndef a(a, b, c):\r\n    ...\r\n```\r\n\r\n### Other\r\n- replaceFunc\r\n```python\r\nfrom devpytools import replaceFunc\r\nIS_DEV = os.getenv(\"IS_DEV\", \"\") == \"true\"\r\n\r\ndef devFunc():\r\n    # predefined results for development\r\n    ...\r\n# replace only if IS_DEV is True\r\n@replaceFunc(devFunc, isEnabled=IS_DEV)\r\ndef prodFunc():\r\n    # time consuming function\r\n    ...\r\n```\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Various dev tools.",
    "version": "0.1.0.dev7",
    "project_urls": {
        "Homepage": "https://github.com/glowlex/devpytools"
    },
    "split_keywords": [
        "tools",
        "cache",
        "dev"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "02e4bc21df4b883695f8b2b2147545c1ed87261e20127ed5c71eb8dac415c15e",
                "md5": "27909a05bba09c875a4542a9957721a8",
                "sha256": "36bb6a1b74108ad77af6eef667de19adf1b943314c6fbe572485748ab60a555d"
            },
            "downloads": -1,
            "filename": "devpytools-0.1.0.dev7-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "27909a05bba09c875a4542a9957721a8",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 8807,
            "upload_time": "2023-11-11T14:50:19",
            "upload_time_iso_8601": "2023-11-11T14:50:19.546395Z",
            "url": "https://files.pythonhosted.org/packages/02/e4/bc21df4b883695f8b2b2147545c1ed87261e20127ed5c71eb8dac415c15e/devpytools-0.1.0.dev7-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "88e92b3a9e8d1a290be82e1364ff12560f975ba0e1e97df17e394f99178b5756",
                "md5": "588d38feb5d43dbfeff97eadcbbbe820",
                "sha256": "91e696573b4271cfe4b5f1030adaea5ea3914cd3f69011b5823788d6be04772a"
            },
            "downloads": -1,
            "filename": "devpytools-0.1.0.dev7.tar.gz",
            "has_sig": false,
            "md5_digest": "588d38feb5d43dbfeff97eadcbbbe820",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 10795,
            "upload_time": "2023-11-11T14:50:20",
            "upload_time_iso_8601": "2023-11-11T14:50:20.921027Z",
            "url": "https://files.pythonhosted.org/packages/88/e9/2b3a9e8d1a290be82e1364ff12560f975ba0e1e97df17e394f99178b5756/devpytools-0.1.0.dev7.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-11 14:50:20",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "glowlex",
    "github_project": "devpytools",
    "github_not_found": true,
    "lcname": "devpytools"
}
        
Elapsed time: 0.14639s