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

Overview

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

Thanks To JetBrains

We develop pyrin using JetBrains products with the awesome open source license provided by JetBrains.

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/
    
     '
    , 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 ignore_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 ignore_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 ignore_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 ignore_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.

Comments
  • [api.swagger]-swagger ui support

    [api.swagger]-swagger ui support

    add each new route into a list in api.swagger package to be able to generate api doc from it. extract param names from args, and param types and keyword args from docs. and register each api module as a dict key, and the values would be all api methods of that module with all info. this package must process the docs in after_packages_loaded() hook of packaging.

    basic feature 
    opened by mononobi 4
  • [converters.deserializer]-internal deserializer

    [converters.deserializer]-internal deserializer

    Add a new concept for internal deserializers to be only accessible inside server. for example prevent using them for query string deserialization. these deserializers must be internal: pool, timedelta

    enhancement basic feature 
    opened by mononobi 3
  • [security.authenticators]-implement authenticators

    [security.authenticators]-implement authenticators

    implement authenticators for admin api, swagger ui and audit api. add a config key in their relevant config store to customize authenticator name. extend admin users to be enable to select which operations is allowed for each admin user. for example, admin api, swagger ui and audit api calls.

    enhancement 
    opened by mononobi 2
  • [validator]-revise string validator length message

    [validator]-revise string validator length message

    revise error message for string validator on invalid length to mention the required min or max length on error. also add data key into options in api exception handlers. also add support for callable min and max values in range and min and max validator. also add a method to those validators to get representation of value to be used for complex types like datetime .... also add lazy=True as default in validation services. on lazy validation do not add data if only one item is available in list. also revise lazy validation message.

    enhancement basic feature 
    opened by mononobi 2
  • [caching]-globalization inputs

    [caching]-globalization inputs

    add an option for caching get method to be able to consider current locale and timezone. this option must be True by default. it should also be added into caching config store with default value. the default value could be overridden per each decorated method.

    enhancement basic feature future 
    opened by mononobi 2
  • [database.orm.sql.operators]-implement operators

    [database.orm.sql.operators]-implement operators

    Implement operators for some sqlalchemy default operators (like, ilike, startswith, istartswith, endswith, iendswith, ...) to consider % and _ in their default behavior.

    enhancement basic feature 
    opened by mononobi 2
  • [application.base]-define a new application hook to be triggered after runtime data is prepared

    [application.base]-define a new application hook to be triggered after runtime data is prepared

    define a new application hook to be triggered after runtime data is prepared. it should be called runtime_data_is_ready or something and it should be fired after prepare_runtime_data hook is done. you should also implement this hook on audit package to run startup audit in it instead of running it in before_application_run. this way the startup audit would also be triggered when running unit tests.

    important: this new hook should be ignored when application is started in scripting mode.

    basic feature 
    opened by mononobi 1
  • [validator]-extend range validators support

    [validator]-extend range validators support

    Enable range validation for string types and also for pk columns. options must be added to different column classes. range utility package must be modified to support this.

    enhancement 
    opened by mononobi 1
  • [admin.page]-extend common metadata

    [admin.page]-extend common metadata

    Add all these configs into common metadata to be returned to client on every page:

    "panel_name", "page_key",, "page_size_key", "ordering_key", "query_param", "pk_name", "locale_key", "timezone_key"

    and also add login metadata to include these common info in it.

    enhancement basic feature 
    opened by mononobi 1
  • [admin]-implement button rendering for * to many relations

    [admin]-implement button rendering for * to many relations

    Implement a way to produce a link button to all related records of a parent record in list view. add a config for list buttons in admin page to set all method names which provide detail info and use it on the client. the info must have current id, register name of related admin page and ...

    enhancement basic feature 
    opened by mononobi 1
  • [validator]-disable fixer

    [validator]-disable fixer

    Add an option for validate methods to disable fixing value. this should be used in validate_for_find and validate methods. and also in all is_valid_* methods.

    invalid wontfix 
    opened by mononobi 1
  • [database.model.mixin]-Add duplicate option to converter mixin

    [database.model.mixin]-Add duplicate option to converter mixin

    Add duplicate option to 'to_dict' method of converter mixin to let duplicate a key with a new name. all docstrings and usages of all places (serializers, ...) must be modified too.

    enhancement future 
    opened by mononobi 0
  • [task_queues.local]-implement local task queues

    [task_queues.local]-implement local task queues

    Implement a package to let user define local tasks which can be run periodically, once, at specific time .... It should be work in a separate thread. Also implement admin page for defining and managing tasks.

    basic feature future 
    opened by mononobi 0
  • [columns]-datetime allow future or past

    [columns]-datetime allow future or past

    add an attribute for all date and time and timestamp columns to allow future or past dates and time. then use it in admin client to disable future or past. if both future and past are not allowed, it must raise an error on server startup. it might be good to also add this options in corresponding validators to be set independently from a column.

    enhancement 
    opened by mononobi 0
Releases(0.5.6)
  • 0.5.6(Jul 16, 2021)

    • Minor code enhancements
    • Enable validated for entity columns by default
    • Minor bug fixes in validation services
    • Implement configurable http response codes for different http methods
    • Enhance swagger schema metadata extraction
    Source code(tar.gz)
    Source code(zip)
  • 0.5.5(Jul 10, 2021)

  • 0.5.4(Jul 10, 2021)

  • 0.5.3(Jul 1, 2021)

    • Updated all dependencies and flask itself
    • Added helper api decorators for most used http methods (post, get, put, patch and delete)
    • Extended validators to be able to use a custom field name in validation errors
    • Added a new validation service for standalone arguments without considering their database column nullability or default value
    Source code(tar.gz)
    Source code(zip)
  • 0.5.2(Jun 25, 2021)

    • Added automatic filtering support for entities
    • Minor bug fixes
    • Revised package manager template
    • Extended path utils
    • Important bug fixes for sqlalchemy updated version
    Source code(tar.gz)
    Source code(zip)
  • 0.5.1(Apr 2, 2021)

  • 0.5.0(Apr 1, 2021)

    • First release to support sqlalchemy 1.4
    • All dependencies upgraded
    • Codes revised to support sqlalchemy 1.4
    • Dropped support for sqlalchemy < 1.4
    • Dropped support for python < 3.6
    • Title case normalizer revised to perform more practical
    • Minor bug fixes
    Source code(tar.gz)
    Source code(zip)
  • 0.4.36(Mar 30, 2021)

    ** This is the last release which works with sqlalchemy < 1.4

    • Extended path utils
    • Added slug utils
    • Added regex utils
    • Code enhancements
    • Minor bug fixes
    Source code(tar.gz)
    Source code(zip)
  • 0.4.35(Mar 25, 2021)

  • 0.4.34(Mar 18, 2021)

  • 0.4.33(Mar 17, 2021)

  • 0.4.32(Mar 16, 2021)

  • 0.4.31(Mar 14, 2021)

  • 0.4.30(Mar 13, 2021)

  • 0.4.29(Mar 13, 2021)

  • 0.4.28(Mar 9, 2021)

    • Enhancements on datetime package
    • Revising model mixins
    • Populating all model mixin caches on server startup for performance boost
    • Added the ability to limit the ordering columns of an entity
    • Always considering UTC timezone for sqlite backend independent from server timezone
    Source code(tar.gz)
    Source code(zip)
  • 0.4.27(Mar 6, 2021)

    • Enhanced datetime range clause generator and between datetime methods
    • Fixed autoincrement columns other than Integer on sqlite backends
    • Added support for timezone handling for datetime columns on sqlite backend
    • Added new helper datetime services
    • Code enhancements
    Source code(tar.gz)
    Source code(zip)
  • 0.4.26(Mar 4, 2021)

    • Extended safe order by to also support queries with row results.
    • Enhance datetime services to preserve server timezone on naive values. it is useful for database backends where timezone support is not available, for example sqlite.
    Source code(tar.gz)
    Source code(zip)
  • 0.4.25(Mar 3, 2021)

  • 0.4.24(Mar 2, 2021)

  • 0.4.23(Mar 1, 2021)

    • Added all common column helpers. such as: GUIDColumn, SequenceColumn, IntegerColumn, BigIntegerColumn, SmallIntegerColumn, DateTimeColumn, DateColumn, TimeColumn, TimeStampColumn, FloatColumn, DecimalColumn, BooleanColumn, TextColumn.
    Source code(tar.gz)
    Source code(zip)
  • 0.4.22(Feb 28, 2021)

  • 0.4.21(Feb 27, 2021)

  • 0.4.20(Feb 26, 2021)

  • 0.4.19(Feb 26, 2021)

    • Add auto validators
    • Integrate columns with validators
    • Improved validators structure
    • Add dict and decimal validators
    • Enhance model mixin classes
    • Minor bug fixes
    • Code enhancements
    Source code(tar.gz)
    Source code(zip)
  • 0.4.18(Feb 19, 2021)

  • 0.4.17(Feb 18, 2021)

  • 0.4.16(Feb 17, 2021)

  • 0.4.15(Feb 16, 2021)

    • Validator keywords revised
    • Added Hidden Column
    • Added transient decorator and context manager
    • Added transient support for session.execute method
    Source code(tar.gz)
    Source code(zip)
  • 0.4.14(Feb 15, 2021)

    • Added FKColumn
    • Added suppress context manager to suppress exceptions
    • Revised populating config keys with null value from environment variables to prevent name clash
    Source code(tar.gz)
    Source code(zip)
Owner
Mohamad Nobakht
Mohamad Nobakht
Free and open source full-stack enterprise framework for agile development of secure database-driven web-based applications, written and programmable in Python.

Readme web2py is a free open source full-stack framework for rapid development of fast, scalable, secure and portable database-driven web-based applic

null 2k Dec 31, 2022
A micro web-framework using asyncio coroutines and chained middleware.

Growler master ' dev Growler is a web framework built atop asyncio, the asynchronous library described in PEP 3156 and added to the standard library i

null 687 Nov 27, 2022
Bromelia-hss implements an HSS by using the Python micro framework Bromélia.

Bromélia HSS bromelia-hss is the second official implementation of a Diameter-based protocol application by using the Python micro framework Bromélia.

henriquemr 7 Nov 2, 2022
The Python micro framework for building web applications.

Flask Flask is a lightweight WSGI web application framework. It is designed to make getting started quick and easy, with the ability to scale up to co

The Pallets Projects 61.5k Jan 6, 2023
bottle.py is a fast and simple micro-framework for python web-applications.

Bottle: Python Web Framework Bottle is a fast, simple and lightweight WSGI micro web-framework for Python. It is distributed as a single file module a

Bottle Micro Web Framework 7.8k Dec 31, 2022
Fast⚡, simple and light💡weight ASGI micro🔬 web🌏-framework for Python🐍.

NanoASGI Asynchronous Python Web Framework NanoASGI is a fast ⚡ , simple and light ?? weight ASGI micro ?? web ?? -framework for Python ?? . It is dis

Kavindu Santhusa 8 Jun 16, 2022
A proof-of-concept CherryPy inspired Python micro framework

Varmkorv Varmkorv is a CherryPy inspired micro framework using Werkzeug. This is just a proof of concept. You are free to use it if you like, or find

Magnus Karlsson 1 Nov 22, 2021
Swagger/OpenAPI First framework for Python on top of Flask with automatic endpoint validation & OAuth2 support

Connexion Connexion is a framework that automagically handles HTTP requests based on OpenAPI Specification (formerly known as Swagger Spec) of your AP

Zalando SE 4.2k Jan 7, 2023
Swagger/OpenAPI First framework for Python on top of Flask with automatic endpoint validation & OAuth2 support

Connexion Connexion is a framework that automagically handles HTTP requests based on OpenAPI Specification (formerly known as Swagger Spec) of your AP

Zalando SE 3.5k Feb 17, 2021
The no-nonsense, minimalist REST and app backend framework for Python developers, with a focus on reliability, correctness, and performance at scale.

The Falcon Web Framework Falcon is a reliable, high-performance Python web framework for building large-scale app backends and microservices. It encou

Falconry 9k Jan 1, 2023
Goblet is an easy-to-use framework that enables developers to quickly spin up fully featured REST APIs with python on GCP

GOBLET Goblet is a framework for writing serverless rest apis in python in google cloud. It allows you to quickly create and deploy python apis backed

Austen 78 Dec 27, 2022
Chisel is a light-weight Python WSGI application framework built for creating well-documented, schema-validated JSON web APIs

chisel Chisel is a light-weight Python WSGI application framework built for creating well-documented, schema-validated JSON web APIs. Here are its fea

Craig Hobbs 2 Dec 2, 2021
Flask-Potion is a RESTful API framework for Flask and SQLAlchemy, Peewee or MongoEngine

Flask-Potion Description Flask-Potion is a powerful Flask extension for building RESTful JSON APIs. Potion features include validation, model resource

DTU Biosustain 491 Dec 8, 2022
Flask-Potion is a RESTful API framework for Flask and SQLAlchemy, Peewee or MongoEngine

Flask-Potion Description Flask-Potion is a powerful Flask extension for building RESTful JSON APIs. Potion features include validation, model resource

DTU Biosustain 484 Feb 3, 2021
Flask Sugar is a web framework for building APIs with Flask, Pydantic and Python 3.6+ type hints.

Flask Sugar is a web framework for building APIs with Flask, Pydantic and Python 3.6+ type hints. check parameters and generate API documents automatically. Flask Sugar是一个基于flask,pyddantic,类型注解的API框架, 可以检查参数并自动生成API文档

null 162 Dec 26, 2022
Loan qualifier app - Loan Qualifier Application Built With Python

Loan Qualifier Application This program is designed to automate the discovery pr

Phil Hills 1 Jan 4, 2022
A public API written in Python using the Flask web framework to determine the direction of a road sign using AI

python-public-API This repository is a public API for solving the problem of the final of the AIIJC competition. The task is to create an AI for the c

Lev 1 Nov 8, 2021
You can use the mvc pattern in your flask application using this extension.

You can use the mvc pattern in your flask application using this extension. Installation Run the follow command to install mvc_flask: $ pip install mv

Marcus Pereira 37 Dec 17, 2022
Dazzler is a Python async UI/Web framework built with aiohttp and react.

Dazzler is a Python async UI/Web framework built with aiohttp and react. Create dazzling fast pages with a layout of Python components and bindings to update from the backend.

Philippe Duval 17 Oct 18, 2022