shelchemy


Nameshelchemy JSON
Version 2.240219.1 PyPI version JSON
download
home_page
SummaryShelve-like dict using sqlalchemy as a backend, and lazy scheduler for resuming tasks
upload_time2024-02-19 09:33:07
maintainer
docs_urlNone
authordavips
requires_python>=3.10,<4.0
licenseGPL
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ![test](https://github.com/shelchemy/shelchemy/workflows/test/badge.svg)
[![codecov](https://codecov.io/gh/shelchemy/shelchemy/branch/main/graph/badge.svg)](https://codecov.io/gh/shelchemy/shelchemy)
<a href="https://pypi.org/project/shelchemy">
<img src="https://img.shields.io/github/v/release/shelchemy/shelchemy?display_name=tag&sort=semver&color=blue" alt="github">
</a>
![Python version](https://img.shields.io/badge/python-3.8%20%7C%203.9-blue.svg)
[![license: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)

[![API documentation](https://img.shields.io/badge/doc-API%20%28auto%29-a0a0a0.svg)](https://shelchemy.github.io/shelchemy)
[![Downloads](https://static.pepy.tech/badge/shelchemy)](https://pepy.tech/project/shelchemy)
![PyPI - Downloads](https://img.shields.io/pypi/dm/shelchemy)

# shelchemy - Dict-like (shelve-like) storage wrapper for any DBMS (SQLAlchemy)
 


## Python installation
### from package
```bash
# Set up a virtualenv. 
python3 -m venv venv
source venv/bin/activate

# Install from PyPI
pip install shelchemy
```

### from source
```bash
git clone https://github.com/shelchemy/shelchemy
cd shelchemy
poetry install
```

### Examples
This library is more useful when used along with `hdict`.
Here are some possible usages by itself.

**Scheduling jobs.**
<details>
<p>

```python3
from time import sleep

from shelchemy.scheduler import Scheduler

# Jobs can be distributed across multiple computers/networks.
names1 = ["a", "b"]
names2 = ["c"]
names3 = ["d", "e"]
storage = {}
# `storage` can be: shelve; URI pointing to a database; or, any dict-like object.
#   Example of a local database: storage="sqlite+pysqlite:////tmp/sqla-test.db"
#   Example of a remote database: storage="mysql+pymysql://user1:password1@hosh.page/db1"
for name in Scheduler(storage, timeout=10) << names1 << names2 << names3:
    print(f"Processing {name}")
    sleep(0.1)
    print(f"{name} processed!")
"""
2023-11-13 00:03:40.115637 'a' is new, starting
Processing a
a processed!
2023-11-13 00:03:40.316130 'a' done
2023-11-13 00:03:40.326101 'b' is new, starting
Processing b
b processed!
2023-11-13 00:03:40.526549 'b' done
2023-11-13 00:03:40.534599 'c' is new, starting
Processing c
c processed!
2023-11-13 00:03:40.735062 'c' done
2023-11-13 00:03:40.745734 'd' is new, starting
Processing d
d processed!
2023-11-13 00:03:40.946152 'd' done
2023-11-13 00:03:40.957263 'e' is new, starting
Processing e
e processed!
2023-11-13 00:03:41.157701 'e' done
"""
```


</p>
</details>

**Persistent dict.**
<details>
<p>

```python3
from shelchemy import sopen
from shelchemy.cache import Cache

d = Cache("sqlite+pysqlite:////tmp/sqla-test.db")
d["x"] = 5
d["b"] = None
print(d["x"], d["b"])
"""
5 None
"""
```

```python3

try:
    d["xxx"]
except KeyError as m:
    print(m)
"""
'xxx'
"""
```

```python3

for k, v in d.items():
    print(k, v)
print("x" in d)
"""
872d417d62b78366a71ab9fee25f14dc None
aed0339093d97301965a4e23dac3424a b'only bytes when autopack=False'
a b'by'
x 5
b None
True
"""
```

```python3

del d["x"]
print("x" in d)
"""
False
"""
```

```python3

print(d)
"""
{'872d417d62b78366a71ab9fee25f14dc': None, 'aed0339093d97301965a4e23dac3424a': b'only bytes when autopack=False', 'a': b'by', 'b': None}
"""
```

```python3

# Using a context manager.
with sopen() as db:
    print("x" in db)
    print(db)

    db["x"] = b"asd"
    print(db)
    print(db["x"] == b"asd")
    print("x" in db)
    print(db.x == b"asd")

    del db["x"]
    print("x" in db)

    db["any string key longer than 40 characters will be hashed depending if the DBMS backend is used"] = None
    print(db)
"""
False
{}
{'x': b'asd'}
True
True
True
False
{'872d417d62b78366a71ab9fee25f14dc': None}
"""
```


</p>
</details>


## Grants
This work was partially supported by Fapesp under supervision of
Prof. André C. P. L. F. de Carvalho at CEPID-CeMEAI (Grants 2013/07375-0 – 2019/01735-0).

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "shelchemy",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.10,<4.0",
    "maintainer_email": "",
    "keywords": "",
    "author": "davips",
    "author_email": "dpsabc@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/38/55/3afaf5751782fc4e8e9721920fc3efcc588438fa1a8dd4d79e2300fee08a/shelchemy-2.240219.1.tar.gz",
    "platform": null,
    "description": "![test](https://github.com/shelchemy/shelchemy/workflows/test/badge.svg)\n[![codecov](https://codecov.io/gh/shelchemy/shelchemy/branch/main/graph/badge.svg)](https://codecov.io/gh/shelchemy/shelchemy)\n<a href=\"https://pypi.org/project/shelchemy\">\n<img src=\"https://img.shields.io/github/v/release/shelchemy/shelchemy?display_name=tag&sort=semver&color=blue\" alt=\"github\">\n</a>\n![Python version](https://img.shields.io/badge/python-3.8%20%7C%203.9-blue.svg)\n[![license: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)\n\n[![API documentation](https://img.shields.io/badge/doc-API%20%28auto%29-a0a0a0.svg)](https://shelchemy.github.io/shelchemy)\n[![Downloads](https://static.pepy.tech/badge/shelchemy)](https://pepy.tech/project/shelchemy)\n![PyPI - Downloads](https://img.shields.io/pypi/dm/shelchemy)\n\n# shelchemy - Dict-like (shelve-like) storage wrapper for any DBMS (SQLAlchemy)\n \n\n\n## Python installation\n### from package\n```bash\n# Set up a virtualenv. \npython3 -m venv venv\nsource venv/bin/activate\n\n# Install from PyPI\npip install shelchemy\n```\n\n### from source\n```bash\ngit clone https://github.com/shelchemy/shelchemy\ncd shelchemy\npoetry install\n```\n\n### Examples\nThis library is more useful when used along with `hdict`.\nHere are some possible usages by itself.\n\n**Scheduling jobs.**\n<details>\n<p>\n\n```python3\nfrom time import sleep\n\nfrom shelchemy.scheduler import Scheduler\n\n# Jobs can be distributed across multiple computers/networks.\nnames1 = [\"a\", \"b\"]\nnames2 = [\"c\"]\nnames3 = [\"d\", \"e\"]\nstorage = {}\n# `storage` can be: shelve; URI pointing to a database; or, any dict-like object.\n#   Example of a local database: storage=\"sqlite+pysqlite:////tmp/sqla-test.db\"\n#   Example of a remote database: storage=\"mysql+pymysql://user1:password1@hosh.page/db1\"\nfor name in Scheduler(storage, timeout=10) << names1 << names2 << names3:\n    print(f\"Processing {name}\")\n    sleep(0.1)\n    print(f\"{name} processed!\")\n\"\"\"\n2023-11-13 00:03:40.115637 'a' is new, starting\nProcessing a\na processed!\n2023-11-13 00:03:40.316130 'a' done\n2023-11-13 00:03:40.326101 'b' is new, starting\nProcessing b\nb processed!\n2023-11-13 00:03:40.526549 'b' done\n2023-11-13 00:03:40.534599 'c' is new, starting\nProcessing c\nc processed!\n2023-11-13 00:03:40.735062 'c' done\n2023-11-13 00:03:40.745734 'd' is new, starting\nProcessing d\nd processed!\n2023-11-13 00:03:40.946152 'd' done\n2023-11-13 00:03:40.957263 'e' is new, starting\nProcessing e\ne processed!\n2023-11-13 00:03:41.157701 'e' done\n\"\"\"\n```\n\n\n</p>\n</details>\n\n**Persistent dict.**\n<details>\n<p>\n\n```python3\nfrom shelchemy import sopen\nfrom shelchemy.cache import Cache\n\nd = Cache(\"sqlite+pysqlite:////tmp/sqla-test.db\")\nd[\"x\"] = 5\nd[\"b\"] = None\nprint(d[\"x\"], d[\"b\"])\n\"\"\"\n5 None\n\"\"\"\n```\n\n```python3\n\ntry:\n    d[\"xxx\"]\nexcept KeyError as m:\n    print(m)\n\"\"\"\n'xxx'\n\"\"\"\n```\n\n```python3\n\nfor k, v in d.items():\n    print(k, v)\nprint(\"x\" in d)\n\"\"\"\n872d417d62b78366a71ab9fee25f14dc None\naed0339093d97301965a4e23dac3424a b'only bytes when autopack=False'\na b'by'\nx 5\nb None\nTrue\n\"\"\"\n```\n\n```python3\n\ndel d[\"x\"]\nprint(\"x\" in d)\n\"\"\"\nFalse\n\"\"\"\n```\n\n```python3\n\nprint(d)\n\"\"\"\n{'872d417d62b78366a71ab9fee25f14dc': None, 'aed0339093d97301965a4e23dac3424a': b'only bytes when autopack=False', 'a': b'by', 'b': None}\n\"\"\"\n```\n\n```python3\n\n# Using a context manager.\nwith sopen() as db:\n    print(\"x\" in db)\n    print(db)\n\n    db[\"x\"] = b\"asd\"\n    print(db)\n    print(db[\"x\"] == b\"asd\")\n    print(\"x\" in db)\n    print(db.x == b\"asd\")\n\n    del db[\"x\"]\n    print(\"x\" in db)\n\n    db[\"any string key longer than 40 characters will be hashed depending if the DBMS backend is used\"] = None\n    print(db)\n\"\"\"\nFalse\n{}\n{'x': b'asd'}\nTrue\nTrue\nTrue\nFalse\n{'872d417d62b78366a71ab9fee25f14dc': None}\n\"\"\"\n```\n\n\n</p>\n</details>\n\n\n## Grants\nThis work was partially supported by Fapesp under supervision of\nProf. Andr\u00e9 C. P. L. F. de Carvalho at CEPID-CeMEAI (Grants 2013/07375-0 \u2013 2019/01735-0).\n",
    "bugtrack_url": null,
    "license": "GPL",
    "summary": "Shelve-like dict using sqlalchemy as a backend, and lazy scheduler for resuming tasks",
    "version": "2.240219.1",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8887a1436e527c26896cdcb1211bd48e2f58bab36c925ec744bfc7efc3903e33",
                "md5": "78cdb429e5e615fa161649bfbbb0c523",
                "sha256": "24a941d3212080530e9a1d8a83c6e431b859f4a51b83355256836c94f46f0e77"
            },
            "downloads": -1,
            "filename": "shelchemy-2.240219.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "78cdb429e5e615fa161649bfbbb0c523",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10,<4.0",
            "size": 23648,
            "upload_time": "2024-02-19T09:33:05",
            "upload_time_iso_8601": "2024-02-19T09:33:05.936417Z",
            "url": "https://files.pythonhosted.org/packages/88/87/a1436e527c26896cdcb1211bd48e2f58bab36c925ec744bfc7efc3903e33/shelchemy-2.240219.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "38553afaf5751782fc4e8e9721920fc3efcc588438fa1a8dd4d79e2300fee08a",
                "md5": "e2ce19cd6ff9f6e5f5b6da04df9c8cbb",
                "sha256": "0bd1a88f0a28caddd2767c4f035cf76f520e1c7b8f28117a614067fcf81434bb"
            },
            "downloads": -1,
            "filename": "shelchemy-2.240219.1.tar.gz",
            "has_sig": false,
            "md5_digest": "e2ce19cd6ff9f6e5f5b6da04df9c8cbb",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10,<4.0",
            "size": 21501,
            "upload_time": "2024-02-19T09:33:07",
            "upload_time_iso_8601": "2024-02-19T09:33:07.305826Z",
            "url": "https://files.pythonhosted.org/packages/38/55/3afaf5751782fc4e8e9721920fc3efcc588438fa1a8dd4d79e2300fee08a/shelchemy-2.240219.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-19 09:33:07",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "shelchemy"
}
        
Elapsed time: 0.18695s