Skip to main content

Lightweight state management engine for posix compliant systems

Project description

Myosin

myosin ci codecov

Modified: 2022-03

Lightweight state management engine.

About

State-driven software architectures are useful for allowing multiple modules to be able to communicate using the same base syntax. The syntax for communication of data is implemented through the state models which represent the the states of different components of the software.

Quickstart

Install myosin from pip

python3 -m pip install myosin

Start by defining a model by creating a class that implements StateModel

from myosin import _PKey
from myosin import StateModel

class User(StateModel):

    def __init__(self, _id: _PKey, name: str, email: str) -> None:
        super().__init__(_id)
        self.name = name
        self.email = email

    @property
    def name(self) -> str:
        return self.__name

    @name.setter
    def name(self, name: str) -> None:
        self.__name = name

    @property
    def email(self) -> str:
        return self.__email

    @email.setter
    def email(self, email: str) -> None:
        self.__email = email

    def serialize(self) -> Dict[str, Any]:
        return {
            'id': self.id,
            'name': self.name,
            'email': self.email
        }

    def deserialize(self, **kwargs) -> None:
        for k, v in kwargs.items():
            setattr(self, k, v)

In the application init load the default state model into the engine:

from myosin import _PKey

usr = User(
    _id=1,
    name="chris",
    email="chris@email.com"
)

with State() as state:
    # register the model into the state engine
    state.load(usr)

In a consumer module you can access the global User model through a checked out copy:

with State() as state:
    # checkout a copy of the user state model
    user = state.checkout(User)
# read properties from the user state model
logging.info("Username: %s", user.name)

In a producer module you can commit to the global User model:

with State() as state:
    # checkout a copy of the user state model
    user = state.checkout(User)
    # modify user state model copy
    user.name = "cS"
    # commit the modified copy
    state.commit(user)

Documentation

Documentation coming soon

Contributions

Contributions are welcome. Please see the issue log and project kanban if you are unsure how to help.

License

This project is licensed under the terms of the MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

myosin-0.1.1.tar.gz (12.1 kB view details)

Uploaded Source

Built Distribution

myosin-0.1.1-py3-none-any.whl (16.4 kB view details)

Uploaded Python 3

File details

Details for the file myosin-0.1.1.tar.gz.

File metadata

  • Download URL: myosin-0.1.1.tar.gz
  • Upload date:
  • Size: 12.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for myosin-0.1.1.tar.gz
Algorithm Hash digest
SHA256 1d285197793f8c434d691833499d968c93867f3c7cd8127e7b1adbd71528e0ad
MD5 25a72ce6a4e1a3f99da8fbb4970bd24b
BLAKE2b-256 52cd941a767e80e773d990681ff1a63dd2b0c5f18ebea33d841dd33dd8f48897

See more details on using hashes here.

File details

Details for the file myosin-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: myosin-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 16.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for myosin-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0b28ac11c26054b04b178d6dd0eda357daa32714b0d7fb22eeeb0513b976ec63
MD5 3cac454641a790b3869e30d50c96ed0d
BLAKE2b-256 cab395076c7cbc6111de0f2f19dd8d22aec2b206681814920f671844239ad896

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page