ormlite


Nameormlite JSON
Version 0.2.1 PyPI version JSON
download
home_page
SummaryTwo way binding from Python Dataclasses to Sqlite tables
upload_time2023-07-04 23:18:37
maintainer
docs_urlNone
author
requires_python>=3.11
licenseCopyright 2023 Charles Taylor 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.
keywords sqlite orm dataclass data query migration
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [Read The Docs](https://ormlite.readthedocs.io/en/latest/)

[PyPI](https://pypi.org/project/ormlite)
<!---
[![Checked with pyright](https://microsoft.github.io/pyright/img/pyright_badge.svg)](https://microsoft.github.io/pyright/)
--->

# Usage

Install:
```
pip install ormlite
```

Sample code:
```python3
from datetime import datetime
from ormlite import connect_to_sqlite, migrate, model, field, select, upsert

@model('persons')
class Person:
  email: str = field(pk=True)
  age: int
  height: str
  last_seen: datetime = datetime.now()

db = connect_to_sqlite("demo.db")
migrate(db)

upsert(db, [Person('me@me.com', 23, "5ft 10in")], update=[])
models = select(Person).where("age = '23'").models(db)
print(list(models))
# Output: [Person(email='me@me.com', age=23, height='5ft 10in', last_seen=datetime.datetime(...))]

db.close()
```


# Motivation
I wanted to query a sqlite database, without writing verbose queries. Previously, for work, I've used django's orm for interacting with sql databases. But for a recent small personal project, I wanted a library to interact with sqlite without depending on an entire web framework.

After I deciding to build my own library, I decided to embrace modern python idioms. So my library is built on top of the dataclasses library in the standard lib. 

To keep scope small, ormlite only interops with sqlite, not other sql databases. I have no future plans to change this.

# Use case

ormlite operates off the principle, that your python source code is the source of truth for the state of the sql tables. Migrations are run in a single step, it checks for differences between your python tables and your sql database. Then it applies sql migrations immediately.

Django & Ruby on Rails, have a separate step whereby migrations are serialized to files. Migrations are thus shared across dev machines, and to production this way. 

Since ormlite doesn't do this, it's not suitable for production deployment or teams of devs.

My use case for the library involves running scripts on my local machine, so I enjoy not dealing with the hassle of an evergrowing list of migrations in my repo.

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "ormlite",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.11",
    "maintainer_email": "",
    "keywords": "sqlite,orm,dataclass,data,query,migration",
    "author": "",
    "author_email": "Charles Taylor <charlestaylor95@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/cb/b8/3a7f638c23338fa80045956c61d968012ec41eeb4cc707e9f1ecedbad9de/ormlite-0.2.1.tar.gz",
    "platform": null,
    "description": "[Read The Docs](https://ormlite.readthedocs.io/en/latest/)\n\n[PyPI](https://pypi.org/project/ormlite)\n<!---\n[![Checked with pyright](https://microsoft.github.io/pyright/img/pyright_badge.svg)](https://microsoft.github.io/pyright/)\n--->\n\n# Usage\n\nInstall:\n```\npip install ormlite\n```\n\nSample code:\n```python3\nfrom datetime import datetime\nfrom ormlite import connect_to_sqlite, migrate, model, field, select, upsert\n\n@model('persons')\nclass Person:\n  email: str = field(pk=True)\n  age: int\n  height: str\n  last_seen: datetime = datetime.now()\n\ndb = connect_to_sqlite(\"demo.db\")\nmigrate(db)\n\nupsert(db, [Person('me@me.com', 23, \"5ft 10in\")], update=[])\nmodels = select(Person).where(\"age = '23'\").models(db)\nprint(list(models))\n# Output: [Person(email='me@me.com', age=23, height='5ft 10in', last_seen=datetime.datetime(...))]\n\ndb.close()\n```\n\n\n# Motivation\nI wanted to query a sqlite database, without writing verbose queries. Previously, for work, I've used django's orm for interacting with sql databases. But for a recent small personal project, I wanted a library to interact with sqlite without depending on an entire web framework.\n\nAfter I deciding to build my own library, I decided to embrace modern python idioms. So my library is built on top of the dataclasses library in the standard lib. \n\nTo keep scope small, ormlite only interops with sqlite, not other sql databases. I have no future plans to change this.\n\n# Use case\n\normlite operates off the principle, that your python source code is the source of truth for the state of the sql tables. Migrations are run in a single step, it checks for differences between your python tables and your sql database. Then it applies sql migrations immediately.\n\nDjango & Ruby on Rails, have a separate step whereby migrations are serialized to files. Migrations are thus shared across dev machines, and to production this way. \n\nSince ormlite doesn't do this, it's not suitable for production deployment or teams of devs.\n\nMy use case for the library involves running scripts on my local machine, so I enjoy not dealing with the hassle of an evergrowing list of migrations in my repo.\n",
    "bugtrack_url": null,
    "license": "Copyright 2023 Charles Taylor  Permission 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:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE 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. ",
    "summary": "Two way binding from Python Dataclasses to Sqlite tables",
    "version": "0.2.1",
    "project_urls": {
        "Github Repo": "https://github.com/CharlesTaylor7/ormlite",
        "Read The Docs": "https://ormlite.readthedocs.io/en/latest/"
    },
    "split_keywords": [
        "sqlite",
        "orm",
        "dataclass",
        "data",
        "query",
        "migration"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "064f4990d6d6eee5176c4de9f2c01bf75942013b91569f5ada6fe541e264edf6",
                "md5": "9a94e488370698cb0531bff607f8d092",
                "sha256": "c670700cbb65b54ee657e8c655307b9f4093e23ab5c1342a5b4d6886bdb4fee9"
            },
            "downloads": -1,
            "filename": "ormlite-0.2.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9a94e488370698cb0531bff607f8d092",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11",
            "size": 11978,
            "upload_time": "2023-07-04T23:18:36",
            "upload_time_iso_8601": "2023-07-04T23:18:36.474980Z",
            "url": "https://files.pythonhosted.org/packages/06/4f/4990d6d6eee5176c4de9f2c01bf75942013b91569f5ada6fe541e264edf6/ormlite-0.2.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "cbb83a7f638c23338fa80045956c61d968012ec41eeb4cc707e9f1ecedbad9de",
                "md5": "d98d0664395f34a226e40a89db587c3b",
                "sha256": "7c7781a416dd70963ad65c450866c2d06a8e18338d9eea0f2a706a139e54a8b3"
            },
            "downloads": -1,
            "filename": "ormlite-0.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "d98d0664395f34a226e40a89db587c3b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 13807,
            "upload_time": "2023-07-04T23:18:37",
            "upload_time_iso_8601": "2023-07-04T23:18:37.896278Z",
            "url": "https://files.pythonhosted.org/packages/cb/b8/3a7f638c23338fa80045956c61d968012ec41eeb4cc707e9f1ecedbad9de/ormlite-0.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-07-04 23:18:37",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "CharlesTaylor7",
    "github_project": "ormlite",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "ormlite"
}
        
Elapsed time: 0.09076s