sqlalchemy-state-machine


Namesqlalchemy-state-machine JSON
Version 1.10.0 PyPI version JSON
download
home_pagehttps://github.com/bigbag/sqlalchemy-state-machine
SummaryHelper for add transitions functionality in sqlalchemy
upload_time2023-08-03 12:06:15
maintainerPavel Liashkov
docs_urlNone
authorPavel Liashkov
requires_python>=3.7
licenseApache License, Version 2.0
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            # sqlalchemy-state-machine


[![CI](https://github.com/bigbag/sqlalchemy-state-machine/workflows/CI/badge.svg)](https://github.com/bigbag/sqlalchemy-state-machine/actions?query=workflow%3ACI)
[![codecov](https://codecov.io/gh/bigbag/sqlalchemy-state-machine/branch/main/graph/badge.svg)](https://codecov.io/gh/bigbag/sqlalchemy-state-machine)
[![pypi](https://img.shields.io/pypi/v/sqlalchemy-state-machine.svg)](https://pypi.python.org/pypi/sqlalchemy-state-machine)
[![downloads](https://img.shields.io/pypi/dm/sqlalchemy-state-machine.svg)](https://pypistats.org/packages/sqlalchemy-state-machine)
[![versions](https://img.shields.io/pypi/pyversions/sqlalchemy-state-machine.svg)](https://github.com/bigbag/sqlalchemy-state-machine)
[![license](https://img.shields.io/github/license/bigbag/sqlalchemy-state-machine.svg)](https://github.com/bigbag/sqlalchemy-state-machine/blob/master/LICENSE)

**sqlalchemy-state-machine** is a helper for add transitions functionality in sqlalchemy.


## Installation

sqlalchemy-state-machine is available on PyPI.
Use pip to install:

    $ pip install sqlalchemy-state-machine


## Basic Usage

```py
import sqlalchemy as sa
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy_state_machine import StateConfig, StateMixin

Base = declarative_base()

NEW = "new"
SENT = "sent"
FAILED = "failed"

class Event(Base, StateMixin):
    __tablename__ = "users"

    state_config = StateConfig(
        initial=NEW,
        states=[NEW, SENT, FAILED],
        transitions=[
            ["set_sent", NEW, SENT],
            ["set_failed", NEW, FAILED],
        ],
    )

    id = sa.Column(sa.Integer, primary_key=True)
    name = sa.Column(sa.String)
    status = sa.Column(sa.String(), nullable=False, index=True)


sa.event.listen(Event, "init", Event.init_state_machine)
sa.event.listen(Event, "load", Event.init_state_machine)

event = Event(name="Event1")

assert event.status == NEW
assert event.set_sent()
assert event.status == SENT
```

## License

sqlalchemy-state-machine is developed and distributed under the Apache 2.0 license.

## Reporting a Security Vulnerability

See our [security policy](https://github.com/bigbag/sqlalchemy-state-machine/security/policy).

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/bigbag/sqlalchemy-state-machine",
    "name": "sqlalchemy-state-machine",
    "maintainer": "Pavel Liashkov",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "pavel.liashkov@protonmail.com",
    "keywords": "",
    "author": "Pavel Liashkov",
    "author_email": "pavel.liashkov@protonmail.com",
    "download_url": "https://files.pythonhosted.org/packages/88/c4/b4e7202cb3640d81c78953e0b6425061459b06100b6e1e0c8164992f1564/sqlalchemy-state-machine-1.10.0.tar.gz",
    "platform": "POSIX",
    "description": "# sqlalchemy-state-machine\n\n\n[![CI](https://github.com/bigbag/sqlalchemy-state-machine/workflows/CI/badge.svg)](https://github.com/bigbag/sqlalchemy-state-machine/actions?query=workflow%3ACI)\n[![codecov](https://codecov.io/gh/bigbag/sqlalchemy-state-machine/branch/main/graph/badge.svg)](https://codecov.io/gh/bigbag/sqlalchemy-state-machine)\n[![pypi](https://img.shields.io/pypi/v/sqlalchemy-state-machine.svg)](https://pypi.python.org/pypi/sqlalchemy-state-machine)\n[![downloads](https://img.shields.io/pypi/dm/sqlalchemy-state-machine.svg)](https://pypistats.org/packages/sqlalchemy-state-machine)\n[![versions](https://img.shields.io/pypi/pyversions/sqlalchemy-state-machine.svg)](https://github.com/bigbag/sqlalchemy-state-machine)\n[![license](https://img.shields.io/github/license/bigbag/sqlalchemy-state-machine.svg)](https://github.com/bigbag/sqlalchemy-state-machine/blob/master/LICENSE)\n\n**sqlalchemy-state-machine** is a helper for add transitions functionality in sqlalchemy.\n\n\n## Installation\n\nsqlalchemy-state-machine is available on PyPI.\nUse pip to install:\n\n    $ pip install sqlalchemy-state-machine\n\n\n## Basic Usage\n\n```py\nimport sqlalchemy as sa\nfrom sqlalchemy.ext.declarative import declarative_base\nfrom sqlalchemy_state_machine import StateConfig, StateMixin\n\nBase = declarative_base()\n\nNEW = \"new\"\nSENT = \"sent\"\nFAILED = \"failed\"\n\nclass Event(Base, StateMixin):\n    __tablename__ = \"users\"\n\n    state_config = StateConfig(\n        initial=NEW,\n        states=[NEW, SENT, FAILED],\n        transitions=[\n            [\"set_sent\", NEW, SENT],\n            [\"set_failed\", NEW, FAILED],\n        ],\n    )\n\n    id = sa.Column(sa.Integer, primary_key=True)\n    name = sa.Column(sa.String)\n    status = sa.Column(sa.String(), nullable=False, index=True)\n\n\nsa.event.listen(Event, \"init\", Event.init_state_machine)\nsa.event.listen(Event, \"load\", Event.init_state_machine)\n\nevent = Event(name=\"Event1\")\n\nassert event.status == NEW\nassert event.set_sent()\nassert event.status == SENT\n```\n\n## License\n\nsqlalchemy-state-machine is developed and distributed under the Apache 2.0 license.\n\n## Reporting a Security Vulnerability\n\nSee our [security policy](https://github.com/bigbag/sqlalchemy-state-machine/security/policy).\n",
    "bugtrack_url": null,
    "license": "Apache License, Version 2.0",
    "summary": "Helper for add transitions functionality in sqlalchemy",
    "version": "1.10.0",
    "project_urls": {
        "Download": "https://pypi.python.org/pypi/sqlalchemy-state-machine",
        "Homepage": "https://github.com/bigbag/sqlalchemy-state-machine"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "35b6889ecde682bf72329ba44ef337735af505e8dba3c16f4f862c2ed37b2b52",
                "md5": "98e9b1ada3833ba95d4f537df35dd496",
                "sha256": "353c1d373454d69275ad98d9aaf66f6b90c51d594e4bef364c638cf56720829f"
            },
            "downloads": -1,
            "filename": "sqlalchemy_state_machine-1.10.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "98e9b1ada3833ba95d4f537df35dd496",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 9109,
            "upload_time": "2023-08-03T12:06:14",
            "upload_time_iso_8601": "2023-08-03T12:06:14.510448Z",
            "url": "https://files.pythonhosted.org/packages/35/b6/889ecde682bf72329ba44ef337735af505e8dba3c16f4f862c2ed37b2b52/sqlalchemy_state_machine-1.10.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "88c4b4e7202cb3640d81c78953e0b6425061459b06100b6e1e0c8164992f1564",
                "md5": "e054ab3a91eaff6dd09b81743986b669",
                "sha256": "d5717e58a9e8304f1067e8f0bd5dee71cd127416c6adb67dd7f3374d368bf7df"
            },
            "downloads": -1,
            "filename": "sqlalchemy-state-machine-1.10.0.tar.gz",
            "has_sig": false,
            "md5_digest": "e054ab3a91eaff6dd09b81743986b669",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 7438,
            "upload_time": "2023-08-03T12:06:15",
            "upload_time_iso_8601": "2023-08-03T12:06:15.480063Z",
            "url": "https://files.pythonhosted.org/packages/88/c4/b4e7202cb3640d81c78953e0b6425061459b06100b6e1e0c8164992f1564/sqlalchemy-state-machine-1.10.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-03 12:06:15",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "bigbag",
    "github_project": "sqlalchemy-state-machine",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "lcname": "sqlalchemy-state-machine"
}
        
Elapsed time: 0.09573s