postmodel


Namepostmodel JSON
Version 0.3.0 PyPI version JSON
download
home_pagehttps://github.com/zeaphoo/postmodel
SummaryEasy async ORM for python, built with relations in mind.
upload_time2024-01-07 11:39:34
maintainerZhuo Wei
docs_urlNone
authorZhuo Wei
requires_python>=3.7
licenseMIT License
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            # postmodel

## Introduction

Postmodel is an easy-to-use ``asyncio`` ORM *(Object Relational Mapper)* inspired by Django and Tortoise ORM.

Postmodel provides 90% Django ORM like API, to ease the migration of developers wishing to switch to ``asyncio``.

Currently, Postmodel provides following features:

* full active-record pattern
* optimistic locking
* 100% code coverage


But, it still have some limits:

* only support Postgresql
* no planing support SQLite, instead it will supports RediSQL
* no support relation


Postmodel is supported on CPython >= 3.6 for PostgreSQL.


## Getting Started

### Installation

You have to install postmodel like this:

```
pip install postmodel
```

### Quick Tutorial

Primary entity of postmodel is ``postmodel.models.Model``.
You can start writing models like this:


```python
from postmodel import models

class Book(models.Model):
    id = models.IntField(pk=True)
    name = models.TextField()
    tag = models.CharField(max_length=120)

    class Meta:
        table = "book_test"

    def __str__(self):
        return self.name
```

After you defined all your models, postmodel needs you to init them, in order to create backward relations between models and match your db client with appropriate models.

You can do it like this:

```python
from postmodel import Postmodel

async def init():
    # Here we connect to a PostgreSQL DB.
    # also specify the app name of "models"
    # which contain models from "app.models"
    await Postmodel.init(
        'postgres://postgres@localhost:54320/test_db',
        modules= [__name__]
    )
    # Generate the schema
    await Postmodel.generate_schemas()
```


Here we create connection to Postgres database, and then we discover & initialise models.

Postmodel currently supports the following databases:

* PostgreSQL (requires ``asyncpg``)

``generate_schema`` generates the schema on an empty database. Postmodel generates schemas in safe mode by default which
includes the ``IF NOT EXISTS`` clause, so you may include it in your main code.


After that you can start using your models:

```python
# Create instance by save
book = Book(id=1, name='Mastering postmdel', tag="orm")
await book.save()

# Or by .create()
await Book.create(id=2, name='Learning Python', tag="python")

# Query

books = await Book.filter(tag="orm").all()
assert len(books) == 1
```



## Contributing

Please have a look at the `Contribution Guide <docs/CONTRIBUTING.md>`_


## License

This project is licensed under the MIT License - see the `LICENSE <LICENSE>`_ file for details

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/zeaphoo/postmodel",
    "name": "postmodel",
    "maintainer": "Zhuo Wei",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "zeaphoo@qq.com",
    "keywords": "",
    "author": "Zhuo Wei",
    "author_email": "zeaphoo@qq.com",
    "download_url": "https://files.pythonhosted.org/packages/94/0f/d37eeb35cc33a70886e4bc5960046b69c3c0a34c8797d3456cfb5b3077b3/postmodel-0.3.0.tar.gz",
    "platform": null,
    "description": "# postmodel\r\n\r\n## Introduction\r\n\r\nPostmodel is an easy-to-use ``asyncio`` ORM *(Object Relational Mapper)* inspired by Django and Tortoise ORM.\r\n\r\nPostmodel provides 90% Django ORM like API, to ease the migration of developers wishing to switch to ``asyncio``.\r\n\r\nCurrently, Postmodel provides following features:\r\n\r\n* full active-record pattern\r\n* optimistic locking\r\n* 100% code coverage\r\n\r\n\r\nBut, it still have some limits:\r\n\r\n* only support Postgresql\r\n* no planing support SQLite, instead it will supports RediSQL\r\n* no support relation\r\n\r\n\r\nPostmodel is supported on CPython >= 3.6 for PostgreSQL.\r\n\r\n\r\n## Getting Started\r\n\r\n### Installation\r\n\r\nYou have to install postmodel like this:\r\n\r\n```\r\npip install postmodel\r\n```\r\n\r\n### Quick Tutorial\r\n\r\nPrimary entity of postmodel is ``postmodel.models.Model``.\r\nYou can start writing models like this:\r\n\r\n\r\n```python\r\nfrom postmodel import models\r\n\r\nclass Book(models.Model):\r\n    id = models.IntField(pk=True)\r\n    name = models.TextField()\r\n    tag = models.CharField(max_length=120)\r\n\r\n    class Meta:\r\n        table = \"book_test\"\r\n\r\n    def __str__(self):\r\n        return self.name\r\n```\r\n\r\nAfter you defined all your models, postmodel needs you to init them, in order to create backward relations between models and match your db client with appropriate models.\r\n\r\nYou can do it like this:\r\n\r\n```python\r\nfrom postmodel import Postmodel\r\n\r\nasync def init():\r\n    # Here we connect to a PostgreSQL DB.\r\n    # also specify the app name of \"models\"\r\n    # which contain models from \"app.models\"\r\n    await Postmodel.init(\r\n        'postgres://postgres@localhost:54320/test_db',\r\n        modules= [__name__]\r\n    )\r\n    # Generate the schema\r\n    await Postmodel.generate_schemas()\r\n```\r\n\r\n\r\nHere we create connection to Postgres database, and then we discover & initialise models.\r\n\r\nPostmodel currently supports the following databases:\r\n\r\n* PostgreSQL (requires ``asyncpg``)\r\n\r\n``generate_schema`` generates the schema on an empty database. Postmodel generates schemas in safe mode by default which\r\nincludes the ``IF NOT EXISTS`` clause, so you may include it in your main code.\r\n\r\n\r\nAfter that you can start using your models:\r\n\r\n```python\r\n# Create instance by save\r\nbook = Book(id=1, name='Mastering postmdel', tag=\"orm\")\r\nawait book.save()\r\n\r\n# Or by .create()\r\nawait Book.create(id=2, name='Learning Python', tag=\"python\")\r\n\r\n# Query\r\n\r\nbooks = await Book.filter(tag=\"orm\").all()\r\nassert len(books) == 1\r\n```\r\n\r\n\r\n\r\n## Contributing\r\n\r\nPlease have a look at the `Contribution Guide <docs/CONTRIBUTING.md>`_\r\n\r\n\r\n## License\r\n\r\nThis project is licensed under the MIT License - see the `LICENSE <LICENSE>`_ file for details\r\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "Easy async ORM for python, built with relations in mind.",
    "version": "0.3.0",
    "project_urls": {
        "Homepage": "https://github.com/zeaphoo/postmodel",
        "Issue Tracker": "https://github.com/zeaphoo/postmodel/issues/",
        "Source Code": "https://github.com/zeaphoo/postmodel/"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f85a3c451f7b04d238759a54460e6e8bbad958ec2425fc6c4cafc35b9b87c593",
                "md5": "2834ce4f054d3b7efab3fdc738a47a41",
                "sha256": "8b133b8d9cd987d576f6287c087b6d7d2f5fbd486949b8633dbf51e5e3bce8fd"
            },
            "downloads": -1,
            "filename": "postmodel-0.3.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2834ce4f054d3b7efab3fdc738a47a41",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 31566,
            "upload_time": "2024-01-07T11:39:33",
            "upload_time_iso_8601": "2024-01-07T11:39:33.064524Z",
            "url": "https://files.pythonhosted.org/packages/f8/5a/3c451f7b04d238759a54460e6e8bbad958ec2425fc6c4cafc35b9b87c593/postmodel-0.3.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "940fd37eeb35cc33a70886e4bc5960046b69c3c0a34c8797d3456cfb5b3077b3",
                "md5": "58274eedeead489d74e7d91ad0a831d3",
                "sha256": "52cbffd1327157bf8f930abf46df8d7ce8378588a7ac43109b4558fcffca331b"
            },
            "downloads": -1,
            "filename": "postmodel-0.3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "58274eedeead489d74e7d91ad0a831d3",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 28016,
            "upload_time": "2024-01-07T11:39:34",
            "upload_time_iso_8601": "2024-01-07T11:39:34.517043Z",
            "url": "https://files.pythonhosted.org/packages/94/0f/d37eeb35cc33a70886e4bc5960046b69c3c0a34c8797d3456cfb5b3077b3/postmodel-0.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-07 11:39:34",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "zeaphoo",
    "github_project": "postmodel",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": false,
    "lcname": "postmodel"
}
        
Elapsed time: 0.17047s