pyrin


Namepyrin JSON
Version 0.6.3 PyPI version JSON
download
home_pagehttps://github.com/mononobi/pyrin
SummaryA rich, fast, performant and easy to use application framework to build apps using Flask on top of it.
upload_time2023-08-20 22:19:13
maintainermono
docs_urlNone
authormono
requires_python>=3.6
licenseBSD-3-Clause
keywords flask python sqlalchemy pyrin core alembic multi-database swagger-uiapplication-framework rest-api dependency-injection ioc admin-panel
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Pyrin

A rich, fast, performant and easy to use application framework 
to build apps using Flask on top of it.

Pyrin is an application framework built on top of Flask micro-framework to make 
life easier for developers who want to develop an enterprise application 
using Flask, without having to make their own core layer and getting better code
design and structure that is more maintainable.

Pyrin could be used as the parent package of an application, so other application 
packages will use its functionality and features to maintain their goals without 
worrying about basic implementations.
It is also possible for application packages to extend existing Pyrin packages.

Pyrin point of view is to build an application which is more decoupled, so making it 
possible to have customized implementations of different packages and also making it 
easier to write unit-test packages.

Another major fact of Pyrin is to avoid centralized locations for application features, so a team
of multiple developers be able to work on the same repository without facing conflicts here
and there. Also reducing the chances of annoying bugs due to forgetting to register
something in somewhere.

## Installing

**Install using pip**:

**`pip install pyrin`**

## Running Tests

To be able to run tests:

1. Pyrin tests are developed using pytest, you should first 
   install pyrin tests dependencies using pip:
   
**`pip install pyrin[tests]`**

2. Now you could execute **`python3 start_unit.py`** to start all unit tests.

## Demo Application

A demo application developed using Pyrin framework is available at: 
[Pyrin-Demo](https://github.com/mononobi/pyrin_demo)

## Contribute In Pyrin Development

We highly appreciate any kind of contributions to Pyrin development.
Fork Pyrin and implement a new feature and make a pull request, we'll let
you know when your work becomes a part of Pyrin.
So, open the project in your IDE and create your pipenv environment.
Then you could start developing Pyrin.

## Extremely Simple Usage Example

The sample code below, is just a rapid showcase on how to develop using Pyrin. 
for a real world application, it is best fit to use the concept of dependency injection 
and IoC which Pyrin is built upon.

To be able to create an application based on Pyrin, the only thing that is required to do
is to subclass from pyrin **`Application`** class in your application package. this is 
needed for Pyrin to be able to find out your application path for generating different 
paths and also loading your application packages. there is no difference where to put 
your subclassed **`Application`**, in this example we put it inside the project's main 
package, inside **`__init__.py`**.


**Sample Project Structure:**

- root_dir
  - demo
    - `__init__.py`
    - `api.py`
    - `models.py`
  - `start.py`

**`__init__.py:`**

```python
from pyrin.application.base import Application


class DemoApplication(Application):
    pass
```

**`models.py:`**

```python
from pyrin.database.model.declarative import CoreEntity
from pyrin.database.orm.sql.schema.columns import GUIDPKColumn, StringColumn, SmallIntegerColumn


class GuestEntity(CoreEntity):

    _table = 'guest'

    id = GUIDPKColumn(name='id')
    name = StringColumn(name='name', max_length=100, validated=True)
    age = SmallIntegerColumn(name='age', min_value=1, validated=True)
```

**`api.py:`**

```python
from pyrin.api.router.decorators import api
from pyrin.core.structs import DTO
from pyrin.database.services import get_current_store

from demo.models import GuestEntity


@api('/introduce/<name>', authenticated=False)
def introduce(name, **options):
    """
    introduce yourself to us.
    ---
    parameters:
      - name: name
        type: string
        description: your name
    responses:
      200:
        schema:
          type: string
          description: a welcome note
    """
    store = get_current_store()
    guest = GuestEntity(name=name)
    store.add(guest)
    return 'Hello dear {name}, you have been added into our database.'.format(name=name)


@api('/guests', authenticated=False)
def guests(**options):
    """
    gets the list of all guests.
    ---
    responses:
      200:
        schema:
          type: array
          items:
            type: object
            properties:
              id:
                type: string
                format: uuid
                description: id of guest
              name:
                type: string
                description: name of guest
              age:
                type: integer
                description: age of guest.
    """
    store = get_current_store()
    return store.query(GuestEntity).all()


@api('/', authenticated=False)
def hello(**options):
    """
    shows the welcome message.
    ---
    responses:
      200:
        schema:
          properties:
            message:
              type: string
              description: welcome message
            current_guests:
              type: integer
              description: count of current guests
    """
    store = get_current_store()
    count = store.query(GuestEntity.id).count()
    result = DTO(message='Welcome to our demo application, please introduce yourself.',
                 current_guests=count)
    return result
```

**`start.py:`**

```python
from demo import DemoApplication


if __name__ == '__main__':
    app = DemoApplication()
    app.run(use_reloader=False)
```

Now you could start application by executing this command in your terminal:

**`python3 start.py`**

Application will be available at **`127.0.0.1:5000`** by default.

Pyrin on default configurations, will use an **`in-memory sqlite`** database.

## Creating a New Pyrin Project

Pyrin has a command line tool that can be used to create a new project.
to use the command line interface of Pyrin, install Pyrin and then open a terminal and write:

```shell
pyrin project
```

after hitting enter, a couple of questions will be asked to create your project, answer
questions accordingly, and your project will be created without a hassle.

## Using Project's Extended Command Line Tool

After creating a new project using **`pyrin project`** command, a **`cli.py`** file will 
be generated in the root of your new project directory. there are a couple of command 
groups that can be used to perform different actions. 
execute each command with **`--help`** option to see all available commands of each group.

- **Builtin Commands:**

  - **`python cli.py alembic`**
  - **`python cli.py babel`**
  - **`python cli.py template`**
  - **`python cli.py security`**
    

- **Integration Commands:**
  - **`python cli.py celery`**

## Integrations

Pyrin has builtin integrations for different services. to use each one of integrations inside
your application, you must install dependencies of that integration.

**Celery:**

**`pip install pyrin[celery]`**

To enable celery after installing its dependencies, open **`settings/packaging.ini`** file
and remove **`pyrin.task_queues.celery`** from the **`ignored_packages`** list.

**Sentry:**

**`pip install pyrin[sentry]`**

To enable sentry after installing its dependencies, open **`settings/packaging.ini`** file
and remove **`pyrin.logging.sentry`** from the **`ignored_packages`** list.

**Redis:**

**`pip install pyrin[redis]`**

To enable redis after installing its dependencies, open **`settings/packaging.ini`** file
and remove **`pyrin.caching.remote.handlers.redis`** from the **`ignored_modules`** list.

**Memcached:**

**`pip install pyrin[memcached]`**

To enable memcached after installing its dependencies, open **`settings/packaging.ini`** file
and remove **`pyrin.caching.remote.handlers.memcached`** from the **`ignored_modules`** list.

## Built-in Swagger UI Support

Pyrin has built-in support for Swagger UI thanks to 
[Flasgger](https://github.com/flasgger/flasgger).
all of your api services are available on swagger without anything needed to be done.
but you can enhance Swagger UI of your application by setting a good **`yaml`**
docstring for your api method views.
You can head over to **`127.0.0.1:5000/swagger`** to test the Swagger UI.

## Inspiration

This project is inspired by the awesome **`Deltapy`** framework by:
- [@abisxir](https://github.com/abisxir)
- [@mvavesal](https://github.com/mvavesal)

Unfortunately I couldn't find any links to it online.

## Hint

`Pyrin` is a greek word and means core.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/mononobi/pyrin",
    "name": "pyrin",
    "maintainer": "mono",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "mononobi@gmail.com",
    "keywords": "flask python sqlalchemy pyrin core alembic multi-database swagger-uiapplication-framework rest-api dependency-injection ioc admin-panel",
    "author": "mono",
    "author_email": "mononobi@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/bd/b3/6e3ac217c4783a9865b392e71ccd5670a9a1d5b48378a07a8d7222ccdfb1/pyrin-0.6.3.tar.gz",
    "platform": null,
    "description": "# Pyrin\n\nA rich, fast, performant and easy to use application framework \nto build apps using Flask on top of it.\n\nPyrin is an application framework built on top of Flask micro-framework to make \nlife easier for developers who want to develop an enterprise application \nusing Flask, without having to make their own core layer and getting better code\ndesign and structure that is more maintainable.\n\nPyrin could be used as the parent package of an application, so other application \npackages will use its functionality and features to maintain their goals without \nworrying about basic implementations.\nIt is also possible for application packages to extend existing Pyrin packages.\n\nPyrin point of view is to build an application which is more decoupled, so making it \npossible to have customized implementations of different packages and also making it \neasier to write unit-test packages.\n\nAnother major fact of Pyrin is to avoid centralized locations for application features, so a team\nof multiple developers be able to work on the same repository without facing conflicts here\nand there. Also reducing the chances of annoying bugs due to forgetting to register\nsomething in somewhere.\n\n## Installing\n\n**Install using pip**:\n\n**`pip install pyrin`**\n\n## Running Tests\n\nTo be able to run tests:\n\n1. Pyrin tests are developed using pytest, you should first \n   install pyrin tests dependencies using pip:\n   \n**`pip install pyrin[tests]`**\n\n2. Now you could execute **`python3 start_unit.py`** to start all unit tests.\n\n## Demo Application\n\nA demo application developed using Pyrin framework is available at: \n[Pyrin-Demo](https://github.com/mononobi/pyrin_demo)\n\n## Contribute In Pyrin Development\n\nWe highly appreciate any kind of contributions to Pyrin development.\nFork Pyrin and implement a new feature and make a pull request, we'll let\nyou know when your work becomes a part of Pyrin.\nSo, open the project in your IDE and create your pipenv environment.\nThen you could start developing Pyrin.\n\n## Extremely Simple Usage Example\n\nThe sample code below, is just a rapid showcase on how to develop using Pyrin. \nfor a real world application, it is best fit to use the concept of dependency injection \nand IoC which Pyrin is built upon.\n\nTo be able to create an application based on Pyrin, the only thing that is required to do\nis to subclass from pyrin **`Application`** class in your application package. this is \nneeded for Pyrin to be able to find out your application path for generating different \npaths and also loading your application packages. there is no difference where to put \nyour subclassed **`Application`**, in this example we put it inside the project's main \npackage, inside **`__init__.py`**.\n\n\n**Sample Project Structure:**\n\n- root_dir\n  - demo\n    - `__init__.py`\n    - `api.py`\n    - `models.py`\n  - `start.py`\n\n**`__init__.py:`**\n\n```python\nfrom pyrin.application.base import Application\n\n\nclass DemoApplication(Application):\n    pass\n```\n\n**`models.py:`**\n\n```python\nfrom pyrin.database.model.declarative import CoreEntity\nfrom pyrin.database.orm.sql.schema.columns import GUIDPKColumn, StringColumn, SmallIntegerColumn\n\n\nclass GuestEntity(CoreEntity):\n\n    _table = 'guest'\n\n    id = GUIDPKColumn(name='id')\n    name = StringColumn(name='name', max_length=100, validated=True)\n    age = SmallIntegerColumn(name='age', min_value=1, validated=True)\n```\n\n**`api.py:`**\n\n```python\nfrom pyrin.api.router.decorators import api\nfrom pyrin.core.structs import DTO\nfrom pyrin.database.services import get_current_store\n\nfrom demo.models import GuestEntity\n\n\n@api('/introduce/<name>', authenticated=False)\ndef introduce(name, **options):\n    \"\"\"\n    introduce yourself to us.\n    ---\n    parameters:\n      - name: name\n        type: string\n        description: your name\n    responses:\n      200:\n        schema:\n          type: string\n          description: a welcome note\n    \"\"\"\n    store = get_current_store()\n    guest = GuestEntity(name=name)\n    store.add(guest)\n    return 'Hello dear {name}, you have been added into our database.'.format(name=name)\n\n\n@api('/guests', authenticated=False)\ndef guests(**options):\n    \"\"\"\n    gets the list of all guests.\n    ---\n    responses:\n      200:\n        schema:\n          type: array\n          items:\n            type: object\n            properties:\n              id:\n                type: string\n                format: uuid\n                description: id of guest\n              name:\n                type: string\n                description: name of guest\n              age:\n                type: integer\n                description: age of guest.\n    \"\"\"\n    store = get_current_store()\n    return store.query(GuestEntity).all()\n\n\n@api('/', authenticated=False)\ndef hello(**options):\n    \"\"\"\n    shows the welcome message.\n    ---\n    responses:\n      200:\n        schema:\n          properties:\n            message:\n              type: string\n              description: welcome message\n            current_guests:\n              type: integer\n              description: count of current guests\n    \"\"\"\n    store = get_current_store()\n    count = store.query(GuestEntity.id).count()\n    result = DTO(message='Welcome to our demo application, please introduce yourself.',\n                 current_guests=count)\n    return result\n```\n\n**`start.py:`**\n\n```python\nfrom demo import DemoApplication\n\n\nif __name__ == '__main__':\n    app = DemoApplication()\n    app.run(use_reloader=False)\n```\n\nNow you could start application by executing this command in your terminal:\n\n**`python3 start.py`**\n\nApplication will be available at **`127.0.0.1:5000`** by default.\n\nPyrin on default configurations, will use an **`in-memory sqlite`** database.\n\n## Creating a New Pyrin Project\n\nPyrin has a command line tool that can be used to create a new project.\nto use the command line interface of Pyrin, install Pyrin and then open a terminal and write:\n\n```shell\npyrin project\n```\n\nafter hitting enter, a couple of questions will be asked to create your project, answer\nquestions accordingly, and your project will be created without a hassle.\n\n## Using Project's Extended Command Line Tool\n\nAfter creating a new project using **`pyrin project`** command, a **`cli.py`** file will \nbe generated in the root of your new project directory. there are a couple of command \ngroups that can be used to perform different actions. \nexecute each command with **`--help`** option to see all available commands of each group.\n\n- **Builtin Commands:**\n\n  - **`python cli.py alembic`**\n  - **`python cli.py babel`**\n  - **`python cli.py template`**\n  - **`python cli.py security`**\n    \n\n- **Integration Commands:**\n  - **`python cli.py celery`**\n\n## Integrations\n\nPyrin has builtin integrations for different services. to use each one of integrations inside\nyour application, you must install dependencies of that integration.\n\n**Celery:**\n\n**`pip install pyrin[celery]`**\n\nTo enable celery after installing its dependencies, open **`settings/packaging.ini`** file\nand remove **`pyrin.task_queues.celery`** from the **`ignored_packages`** list.\n\n**Sentry:**\n\n**`pip install pyrin[sentry]`**\n\nTo enable sentry after installing its dependencies, open **`settings/packaging.ini`** file\nand remove **`pyrin.logging.sentry`** from the **`ignored_packages`** list.\n\n**Redis:**\n\n**`pip install pyrin[redis]`**\n\nTo enable redis after installing its dependencies, open **`settings/packaging.ini`** file\nand remove **`pyrin.caching.remote.handlers.redis`** from the **`ignored_modules`** list.\n\n**Memcached:**\n\n**`pip install pyrin[memcached]`**\n\nTo enable memcached after installing its dependencies, open **`settings/packaging.ini`** file\nand remove **`pyrin.caching.remote.handlers.memcached`** from the **`ignored_modules`** list.\n\n## Built-in Swagger UI Support\n\nPyrin has built-in support for Swagger UI thanks to \n[Flasgger](https://github.com/flasgger/flasgger).\nall of your api services are available on swagger without anything needed to be done.\nbut you can enhance Swagger UI of your application by setting a good **`yaml`**\ndocstring for your api method views.\nYou can head over to **`127.0.0.1:5000/swagger`** to test the Swagger UI.\n\n## Inspiration\n\nThis project is inspired by the awesome **`Deltapy`** framework by:\n- [@abisxir](https://github.com/abisxir)\n- [@mvavesal](https://github.com/mvavesal)\n\nUnfortunately I couldn't find any links to it online.\n\n## Hint\n\n`Pyrin` is a greek word and means core.\n",
    "bugtrack_url": null,
    "license": "BSD-3-Clause",
    "summary": "A rich, fast, performant and easy to use application framework to build apps using Flask on top of it.",
    "version": "0.6.3",
    "project_urls": {
        "Code": "https://github.com/mononobi/pyrin",
        "Homepage": "https://github.com/mononobi/pyrin",
        "Issue tracker": "https://github.com/mononobi/pyrin/issues"
    },
    "split_keywords": [
        "flask",
        "python",
        "sqlalchemy",
        "pyrin",
        "core",
        "alembic",
        "multi-database",
        "swagger-uiapplication-framework",
        "rest-api",
        "dependency-injection",
        "ioc",
        "admin-panel"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3f9141720594c3c3221a8d3fa0510602479584189b9b769e8eb30a43f6661bdf",
                "md5": "3f2ffca287fab8f893f5136de021c9c5",
                "sha256": "22944c59776d05a90931f82063cde43049be2de3e9c0788cc89885eb15837d8e"
            },
            "downloads": -1,
            "filename": "pyrin-0.6.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3f2ffca287fab8f893f5136de021c9c5",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 778614,
            "upload_time": "2023-08-20T22:19:06",
            "upload_time_iso_8601": "2023-08-20T22:19:06.265453Z",
            "url": "https://files.pythonhosted.org/packages/3f/91/41720594c3c3221a8d3fa0510602479584189b9b769e8eb30a43f6661bdf/pyrin-0.6.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bdb36e3ac217c4783a9865b392e71ccd5670a9a1d5b48378a07a8d7222ccdfb1",
                "md5": "fce076ba8c740c6955ee7ae5d4a0ca83",
                "sha256": "92518a0349f58db4b9f1af4dafe61464b92ed77eb08c5d4c4cceb05a14e80e72"
            },
            "downloads": -1,
            "filename": "pyrin-0.6.3.tar.gz",
            "has_sig": false,
            "md5_digest": "fce076ba8c740c6955ee7ae5d4a0ca83",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 492694,
            "upload_time": "2023-08-20T22:19:13",
            "upload_time_iso_8601": "2023-08-20T22:19:13.400758Z",
            "url": "https://files.pythonhosted.org/packages/bd/b3/6e3ac217c4783a9865b392e71ccd5670a9a1d5b48378a07a8d7222ccdfb1/pyrin-0.6.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-20 22:19:13",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "mononobi",
    "github_project": "pyrin",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "pyrin"
}
        
Elapsed time: 0.21414s