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
Online Boutique is a cloud-native microservices demo application

Online Boutique is a cloud-native microservices demo application. Online Boutique consists of a 10-tier microservices application. The application is

Matt Reider 1 Oct 22, 2021
Library for building WebSocket servers and clients in Python

What is websockets? websockets is a library for building WebSocket servers and clients in Python with a focus on correctness and simplicity. Built on

Aymeric Augustin 4.3k Dec 31, 2022
Sierra is a lightweight Python framework for building and integrating web applications

A lightweight Python framework for building and Integrating Web Applications. Sierra is a Python3 library for building and integrating web applications with HTML and CSS using simple enough syntax. Y

83 Sep 23, 2022
A python application to log QSOs directly to QRZ.com from the command line

qrzlogger This script is a QRZ.com command line QSO logger. It does the following: asks the user for a call sign displays available call sign info pul

Michael Clemens 15 Jul 16, 2021
Official mirror of https://gitlab.com/pgjones/quart

Quart Quart is an async Python web microframework. Using Quart you can, render and serve HTML templates, write (RESTful) JSON APIs, serve WebSockets,

Phil Jones 2 Oct 05, 2022
A simple Tornado based framework designed to accelerate web service development

Toto Toto is a small framework intended to accelerate web service development. It is built on top of Tornado and can currently use MySQL, MongoDB, Pos

Jeremy Olmsted-Thompson 61 Apr 06, 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 491 Dec 08, 2022
Asita is a web application framework for python based on express-js framework.

Asita is a web application framework for python. It is designed to be easy to use and be more easy for javascript users to use python frameworks because it is based on express-js framework.

Mattéo 4 Nov 16, 2021
REST API framework designed for human beings

Eve Eve is an open source Python REST API framework designed for human beings. It allows to effortlessly build and deploy highly customizable, fully f

eve 6.6k Jan 07, 2023
Fully featured framework for fast, easy and documented API development with Flask

Flask RestPlus IMPORTANT NOTICE: This project has been forked to Flask-RESTX and will be maintained by by the python-restx organization. Flask-RESTPlu

Axel H. 2.7k Jan 04, 2023
🦍 The Cloud-Native API Gateway

Kong or Kong API Gateway is a cloud-native, platform-agnostic, scalable API Gateway distinguished for its high performance and extensibility via plugi

Kong 33.8k Jan 09, 2023
Microservice example with Python, Faust-Streaming and Kafka (Redpanda)

Microservices Orchestration with Python, Faust-Streaming and Kafka (Redpanda) Example project for PythonBenin meetup. It demonstrates how to use Faust

Lé 3 Jun 13, 2022
A simple todo app using flask and sqlachemy

TODO app This is a simple TODO app made using Flask. Packages used: DoodleCSS Special thanks to Chris McCormick (@mccrmx) :) Flask Flask-SQLAlchemy Fl

Lenin 1 Dec 26, 2021
Web APIs for Django. 🎸

Django REST framework Awesome web-browsable Web APIs. Full documentation for the project is available at https://www.django-rest-framework.org/. Fundi

Encode 24.7k Jan 03, 2023
A comprehensive reference for all topics related to building and maintaining microservices

This pandect (πανδέκτης is Ancient Greek for encyclopedia) was created to help you find and understand almost anything related to Microservices that i

Ivan Bilan 64 Dec 09, 2022
The Web framework for perfectionists with deadlines.

Django Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design. Thanks for checking it out. All docu

Django 67.9k Dec 29, 2022
The lightning-fast ASGI server. ?

The lightning-fast ASGI server. Documentation: https://www.uvicorn.org Community: https://discuss.encode.io/c/uvicorn Requirements: Python 3.6+ (For P

Encode 6k Jan 03, 2023
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
Web framework based on type hint。

Hint API 中文 | English 基于 Type hint 的 Web 框架 hintapi 文档 hintapi 实现了 WSGI 接口,并使用 Radix Tree 进行路由查找。是最快的 Python web 框架之一。一切特性都服务于快速开发高性能的 Web 服务。 大量正确的类型

Aber 19 Dec 02, 2022
Endpoints is a lightweight REST api framework written in python and used in multiple production systems that handle millions of requests daily.

Endpoints Quickest API builder in the West! Endpoints is a lightweight REST api framework written in python and used in multiple production systems th

Jay Marcyes 30 Mar 05, 2022