freak


Namefreak JSON
Version 0.0.1 PyPI version JSON
download
home_pagehttps://github.com/danielgafni/freak
SummaryRemote application state control
upload_time2023-03-27 16:29:30
maintainer
docs_urlNone
authorDaniel Gafni
requires_python>=3.8,<4.0
licenseMIT
keywords state control remote application
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Freak

Control.

Control your application state with a single line of code.

Freak is using `pydantic` to define the state, supports nested models, partial updates, data validation, and uses `FastAPI` to serve the state over HTTP.

## Installation
```shell
pip install freak
```

## Usage

Define a `pydantic` model and pass it to the `control` function.

```python
from freak import control
from pydantic import BaseModel

class State(BaseModel):
    foo: str = "bar"

state = State()
control(state)
```

The `state` object will now be automatically served over HTTP.

Freak generates `/get/<field>` and `/set/<field>` endpoints for each field in the model, as well as the following endpoints for the root state object:
 - `/get` (`GET`)
 - `/set` (`PATCH`)
 - `/reset` (`DELETE`)
 - `/get_from_path` (`GET`) - which allows to get a value from the state using dot-notation (like `my.inner.field.`)

The `foo` field can now be modified externally by sending a PUT request to the Freak server, which has been automatically started in the background:

```shell
curl -X PUT localhost:4444/set/foo?value=baz
```

At the same time, the `state` object cat be used in the program. Freak will always modify it in place. This can be helpful for long-running programs that need to be controlled externally, like:
 - training a neural network
 - running a bot
 - etc.

Freak supports nested models and partial updates. Consider the following model:

```python
from pydantic import BaseModel

class Bar(BaseModel):
    foo: str = "bar"
    baz: str = "qux"

class State(BaseModel):
    bar: Bar = Bar()
```

Freak will generate `put` endpoints for the `foo` and `baz` fields, and a `patch` endpoint for the `bar` field (as it's a `pydantic` model itself). This `patch` endpoint supports partial updates:

```shell
curl -X PATCH localhost:4444/set/bar -d '{"foo": "baz"}'
```

Because Freak is using `FastAPI`, it's possible to use auto-generated documentation to interact with the Freak server. The interactive documentation can be accessed at Freak's main endpoint, which by default is `localhost:4444`.

The following screenshot shows the generated endpoints for the DL [example](https://github.com/danielgafni/freak/blob/master/examples/dl_example.py):

![Sample Generated Docs](https://raw.githubusercontent.com/danielgafni/freak/master/resources/swagger.png)

## Development

### Installation

```shell
poetry install
poetry run pre-commit install
```
### Testing

```shell
poetry run pytest
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/danielgafni/freak",
    "name": "freak",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8,<4.0",
    "maintainer_email": "",
    "keywords": "state,control,remote,application",
    "author": "Daniel Gafni",
    "author_email": "danielgafni16@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/ff/06/893cf3b1b525e1e19e6cb25ee92f9da6b3e482c81ff3656780b94039dd7a/freak-0.0.1.tar.gz",
    "platform": null,
    "description": "# Freak\n\nControl.\n\nControl your application state with a single line of code.\n\nFreak is using `pydantic` to define the state, supports nested models, partial updates, data validation, and uses `FastAPI` to serve the state over HTTP.\n\n## Installation\n```shell\npip install freak\n```\n\n## Usage\n\nDefine a `pydantic` model and pass it to the `control` function.\n\n```python\nfrom freak import control\nfrom pydantic import BaseModel\n\nclass State(BaseModel):\n    foo: str = \"bar\"\n\nstate = State()\ncontrol(state)\n```\n\nThe `state` object will now be automatically served over HTTP.\n\nFreak generates `/get/<field>` and `/set/<field>` endpoints for each field in the model, as well as the following endpoints for the root state object:\n - `/get` (`GET`)\n - `/set` (`PATCH`)\n - `/reset` (`DELETE`)\n - `/get_from_path` (`GET`) - which allows to get a value from the state using dot-notation (like `my.inner.field.`)\n\nThe `foo` field can now be modified externally by sending a PUT request to the Freak server, which has been automatically started in the background:\n\n```shell\ncurl -X PUT localhost:4444/set/foo?value=baz\n```\n\nAt the same time, the `state` object cat be used in the program. Freak will always modify it in place. This can be helpful for long-running programs that need to be controlled externally, like:\n - training a neural network\n - running a bot\n - etc.\n\nFreak supports nested models and partial updates. Consider the following model:\n\n```python\nfrom pydantic import BaseModel\n\nclass Bar(BaseModel):\n    foo: str = \"bar\"\n    baz: str = \"qux\"\n\nclass State(BaseModel):\n    bar: Bar = Bar()\n```\n\nFreak will generate `put` endpoints for the `foo` and `baz` fields, and a `patch` endpoint for the `bar` field (as it's a `pydantic` model itself). This `patch` endpoint supports partial updates:\n\n```shell\ncurl -X PATCH localhost:4444/set/bar -d '{\"foo\": \"baz\"}'\n```\n\nBecause Freak is using `FastAPI`, it's possible to use auto-generated documentation to interact with the Freak server. The interactive documentation can be accessed at Freak's main endpoint, which by default is `localhost:4444`.\n\nThe following screenshot shows the generated endpoints for the DL [example](https://github.com/danielgafni/freak/blob/master/examples/dl_example.py):\n\n![Sample Generated Docs](https://raw.githubusercontent.com/danielgafni/freak/master/resources/swagger.png)\n\n## Development\n\n### Installation\n\n```shell\npoetry install\npoetry run pre-commit install\n```\n### Testing\n\n```shell\npoetry run pytest\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Remote application state control",
    "version": "0.0.1",
    "split_keywords": [
        "state",
        "control",
        "remote",
        "application"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c1157fa7b8184414e5a63de8588ef43e8c4c01599105b7e0b1d9f0477f0ab0b9",
                "md5": "b94503e4c2d64b515df821b9584b2009",
                "sha256": "f2f6847756107106d1f292b70216001cd56b37216385db08dcd43a5c479f6d4e"
            },
            "downloads": -1,
            "filename": "freak-0.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b94503e4c2d64b515df821b9584b2009",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8,<4.0",
            "size": 7340,
            "upload_time": "2023-03-27T16:29:29",
            "upload_time_iso_8601": "2023-03-27T16:29:29.557378Z",
            "url": "https://files.pythonhosted.org/packages/c1/15/7fa7b8184414e5a63de8588ef43e8c4c01599105b7e0b1d9f0477f0ab0b9/freak-0.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ff06893cf3b1b525e1e19e6cb25ee92f9da6b3e482c81ff3656780b94039dd7a",
                "md5": "a64c533234fa68514149bc4b34cc50b2",
                "sha256": "61033217fc2320e53c4c5d3e10cd22664973b620e18ea1294ad6198a2f043236"
            },
            "downloads": -1,
            "filename": "freak-0.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "a64c533234fa68514149bc4b34cc50b2",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8,<4.0",
            "size": 7180,
            "upload_time": "2023-03-27T16:29:30",
            "upload_time_iso_8601": "2023-03-27T16:29:30.920141Z",
            "url": "https://files.pythonhosted.org/packages/ff/06/893cf3b1b525e1e19e6cb25ee92f9da6b3e482c81ff3656780b94039dd7a/freak-0.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-03-27 16:29:30",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "danielgafni",
    "github_project": "freak",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "freak"
}
        
Elapsed time: 0.07369s