fastorm


Namefastorm JSON
Version 0.0.17 PyPI version JSON
download
home_pagehttps://github.com/luckydonald/fastorm
SummaryFastORM framework, easy to learn, fast to code
upload_time2024-07-21 21:41:19
maintainerNone
docs_urlNone
authorluckydonald
requires_python>=3.10.0
licenseNone
keywords
VCS
bugtrack_url
requirements flit asyncpg luckydonald-utils typeguard pydantic coverage psycopg2-binary
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # FastORM
### ORM for async postgres
##### Beta

FastORM is a modern, fast (async), database library for projects with Python 3.10+ based on standard Python type hints.

The key features are:
 - Async postgres
 - Tested to work with Python 3.10

#### Install
```
pip install fastorm
```

#### Example
> See [example.py](example.py) for more examples.

Let's define some tables, to show off the capabilities.

```py
class State(str, Enum):
    RUNNING = 'running'
    ABORTED = 'stopped'
    COMPLETED = 'done'
# end class


class User(FastORM):
    _ignored_fields = []
    _primary_keys = ['id']
    _automatic_fields = ['id']
    _table_name = 'user'

    id: Optional[int]  # Optional because automatically filled (_automatic_fields)
    name: str


class Auction(FastORM):
    _ignored_fields = []
    _primary_keys = ['id']
    _automatic_fields = ['id']
    _table_name = 'auction'

    id: Optional[int]  # Optional because automatically filled (_automatic_fields)
    owner: Union[int, User]  # can be provided by int or the native object
    previous_owner: Optional[User]  # Optional because nullable
    state: State  # Enum support :D
    title: str
    subtitle: Optional[str]  # nullable
    description: str
    start_date: datetime  # datetime support
    end_date: datetime
    metadata: JSONType
    deleted: bool
    chat_id: int
```

Now you can quickly write classes to the database:

```py
conn = await FastORM.create_connection('postgresql://user:password@postgres_host/database')


user = User(id=None, name="hunter24")  # id will be filled by the database
await owner_user.insert(conn=conn)  # set's the id, too.

auction = Auction(
    id=None,  # gonna be automatic if `insert(…, ignore_setting_automatic_fields=False)` (default).
    # two ways of setting references to other tables:
    # by the actual value, in this case the numeric id
    owner=user.id,  
    # or via a different object,
    # it will use the id field (internally set by `User._primary_keys`) to determine the actual values.
    previous_owner=user,  
    state=State.RUNNING,  # enum will be a string in the database
    title="I sell my soul", subtitle="Slightly used",
    description="You only get a share though, others claim ownership, too.",
    start_date=datetime.now(), end_date=datetime.now() + timedelta(days=5),  # datetimes just works
    metadata={"just": ["json", "stuff", 111, datetime.now()]},  # will be native JSONB. You can have datetimes and your own classes in there as well, see `FastORM._set_up_connection`.
    deleted=False,
    chat_id=9223372036854775807,  # note, this database field must be BIGINT for such large numbers
)
await auction.insert(conn=conn)
```

Basic lookups are easy, too.

```py
# single lookup, returns one element or None
user = await User.get(name="hunter24")
user = await User.get(id=1234)

# list of results (list can have length 0)
all_running_auctions = Auction.select(state=State.RUNNING)
```

Of course updating and deleting is possible too.

```py
auction.state = State.COMPLETED
await auction.update()
```
```py
await user.delete()
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/luckydonald/fastorm",
    "name": "fastorm",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10.0",
    "maintainer_email": null,
    "keywords": null,
    "author": "luckydonald",
    "author_email": "fastorm+code@luckydonald.de",
    "download_url": "https://files.pythonhosted.org/packages/eb/9f/e19e3377060bfc5a61ed324a64201d4baa9dbba17e5e1333a3f1703ea698/fastorm-0.0.17.tar.gz",
    "platform": null,
    "description": "# FastORM\n### ORM for async postgres\n##### Beta\n\nFastORM is a modern, fast (async), database library for projects with Python 3.10+ based on standard Python type hints.\n\nThe key features are:\n - Async postgres\n - Tested to work with Python 3.10\n\n#### Install\n```\npip install fastorm\n```\n\n#### Example\n> See [example.py](example.py) for more examples.\n\nLet's define some tables, to show off the capabilities.\n\n```py\nclass State(str, Enum):\n    RUNNING = 'running'\n    ABORTED = 'stopped'\n    COMPLETED = 'done'\n# end class\n\n\nclass User(FastORM):\n    _ignored_fields = []\n    _primary_keys = ['id']\n    _automatic_fields = ['id']\n    _table_name = 'user'\n\n    id: Optional[int]  # Optional because automatically filled (_automatic_fields)\n    name: str\n\n\nclass Auction(FastORM):\n    _ignored_fields = []\n    _primary_keys = ['id']\n    _automatic_fields = ['id']\n    _table_name = 'auction'\n\n    id: Optional[int]  # Optional because automatically filled (_automatic_fields)\n    owner: Union[int, User]  # can be provided by int or the native object\n    previous_owner: Optional[User]  # Optional because nullable\n    state: State  # Enum support :D\n    title: str\n    subtitle: Optional[str]  # nullable\n    description: str\n    start_date: datetime  # datetime support\n    end_date: datetime\n    metadata: JSONType\n    deleted: bool\n    chat_id: int\n```\n\nNow you can quickly write classes to the database:\n\n```py\nconn = await FastORM.create_connection('postgresql://user:password@postgres_host/database')\n\n\nuser = User(id=None, name=\"hunter24\")  # id will be filled by the database\nawait owner_user.insert(conn=conn)  # set's the id, too.\n\nauction = Auction(\n    id=None,  # gonna be automatic if `insert(\u2026, ignore_setting_automatic_fields=False)` (default).\n    # two ways of setting references to other tables:\n    # by the actual value, in this case the numeric id\n    owner=user.id,  \n    # or via a different object,\n    # it will use the id field (internally set by `User._primary_keys`) to determine the actual values.\n    previous_owner=user,  \n    state=State.RUNNING,  # enum will be a string in the database\n    title=\"I sell my soul\", subtitle=\"Slightly used\",\n    description=\"You only get a share though, others claim ownership, too.\",\n    start_date=datetime.now(), end_date=datetime.now() + timedelta(days=5),  # datetimes just works\n    metadata={\"just\": [\"json\", \"stuff\", 111, datetime.now()]},  # will be native JSONB. You can have datetimes and your own classes in there as well, see `FastORM._set_up_connection`.\n    deleted=False,\n    chat_id=9223372036854775807,  # note, this database field must be BIGINT for such large numbers\n)\nawait auction.insert(conn=conn)\n```\n\nBasic lookups are easy, too.\n\n```py\n# single lookup, returns one element or None\nuser = await User.get(name=\"hunter24\")\nuser = await User.get(id=1234)\n\n# list of results (list can have length 0)\nall_running_auctions = Auction.select(state=State.RUNNING)\n```\n\nOf course updating and deleting is possible too.\n\n```py\nauction.state = State.COMPLETED\nawait auction.update()\n```\n```py\nawait user.delete()\n```\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "FastORM framework, easy to learn, fast to code",
    "version": "0.0.17",
    "project_urls": {
        "Documentation": "https://github.com/luckydonald/fastorm",
        "Homepage": "https://github.com/luckydonald/fastorm"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "7016ab268ea371f30fdbf6b15eba363e1595e7a70af56fe7d4709d7288ad5e70",
                "md5": "5de27a906cc20eacc363d36ca447fd77",
                "sha256": "9699c8c79fdd8b3aa4f2f23cbc3eb2ca727cec534e029489031ab598f7105019"
            },
            "downloads": -1,
            "filename": "fastorm-0.0.17-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5de27a906cc20eacc363d36ca447fd77",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10.0",
            "size": 46014,
            "upload_time": "2024-07-21T21:41:17",
            "upload_time_iso_8601": "2024-07-21T21:41:17.440765Z",
            "url": "https://files.pythonhosted.org/packages/70/16/ab268ea371f30fdbf6b15eba363e1595e7a70af56fe7d4709d7288ad5e70/fastorm-0.0.17-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "eb9fe19e3377060bfc5a61ed324a64201d4baa9dbba17e5e1333a3f1703ea698",
                "md5": "e108031c711f70f2ae736bfb32a552ed",
                "sha256": "cc4f7326e4837472f245668b04f7c81e191a22187a68caca06266cfc1ffc5c31"
            },
            "downloads": -1,
            "filename": "fastorm-0.0.17.tar.gz",
            "has_sig": false,
            "md5_digest": "e108031c711f70f2ae736bfb32a552ed",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10.0",
            "size": 74302,
            "upload_time": "2024-07-21T21:41:19",
            "upload_time_iso_8601": "2024-07-21T21:41:19.961384Z",
            "url": "https://files.pythonhosted.org/packages/eb/9f/e19e3377060bfc5a61ed324a64201d4baa9dbba17e5e1333a3f1703ea698/fastorm-0.0.17.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-21 21:41:19",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "luckydonald",
    "github_project": "fastorm",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "flit",
            "specs": [
                [
                    "==",
                    "3.4.0"
                ]
            ]
        },
        {
            "name": "asyncpg",
            "specs": [
                [
                    "==",
                    "0.24.0"
                ]
            ]
        },
        {
            "name": "luckydonald-utils",
            "specs": [
                [
                    "==",
                    "0.83"
                ]
            ]
        },
        {
            "name": "typeguard",
            "specs": [
                [
                    "==",
                    "2.13.0"
                ]
            ]
        },
        {
            "name": "pydantic",
            "specs": [
                [
                    "==",
                    "1.8.2"
                ]
            ]
        },
        {
            "name": "coverage",
            "specs": [
                [
                    "==",
                    "6.0.2"
                ]
            ]
        },
        {
            "name": "psycopg2-binary",
            "specs": [
                [
                    "==",
                    "2.9.1"
                ]
            ]
        }
    ],
    "lcname": "fastorm"
}
        
Elapsed time: 0.58759s