Skip to main content

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

Project description

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]

  1. 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

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:

from pyrin.application.base import Application


class DemoApplication(Application):
    pass

models.py:

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:

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:

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:

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. 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:

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

Hint

Pyrin is a greek word and means core.

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

pyrin-0.6.3.tar.gz (492.7 kB view details)

Uploaded Source

Built Distribution

pyrin-0.6.3-py3-none-any.whl (778.6 kB view details)

Uploaded Python 3

File details

Details for the file pyrin-0.6.3.tar.gz.

File metadata

  • Download URL: pyrin-0.6.3.tar.gz
  • Upload date:
  • Size: 492.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.17

File hashes

Hashes for pyrin-0.6.3.tar.gz
Algorithm Hash digest
SHA256 92518a0349f58db4b9f1af4dafe61464b92ed77eb08c5d4c4cceb05a14e80e72
MD5 fce076ba8c740c6955ee7ae5d4a0ca83
BLAKE2b-256 bdb36e3ac217c4783a9865b392e71ccd5670a9a1d5b48378a07a8d7222ccdfb1

See more details on using hashes here.

File details

Details for the file pyrin-0.6.3-py3-none-any.whl.

File metadata

  • Download URL: pyrin-0.6.3-py3-none-any.whl
  • Upload date:
  • Size: 778.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.17

File hashes

Hashes for pyrin-0.6.3-py3-none-any.whl
Algorithm Hash digest
SHA256 22944c59776d05a90931f82063cde43049be2de3e9c0788cc89885eb15837d8e
MD5 3f2ffca287fab8f893f5136de021c9c5
BLAKE2b-256 3f9141720594c3c3221a8d3fa0510602479584189b9b769e8eb30a43f6661bdf

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