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
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
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
Async Python 3.6+ web server/framework | Build fast. Run fast.

Sanic | Build fast. Run fast. Build Docs Package Support Stats Sanic is a Python 3.6+ web server and web framework that's written to go fast. It allow

Sanic Community Organization 16.7k Dec 28, 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
cirrina is an opinionated asynchronous web framework based on aiohttp

cirrina cirrina is an opinionated asynchronous web framework based on aiohttp. Features: HTTP Server Websocket Server JSON RPC Server Shared sessions

André Roth 32 Mar 05, 2022
APIFlask is a lightweight Python web API framework based on Flask and marshmallow-code projects

APIFlask APIFlask is a lightweight Python web API framework based on Flask and marshmallow-code projects. It's easy to use, highly customizable, ORM/O

Grey Li 705 Jan 04, 2023
NO LONGER MAINTAINED - A Flask extension for creating simple ReSTful JSON APIs from SQLAlchemy models.

NO LONGER MAINTAINED This repository is no longer maintained due to lack of time. You might check out the fork https://github.com/mrevutskyi/flask-res

1k Jan 04, 2023
JustPy is an object-oriented, component based, high-level Python Web Framework

JustPy Docs and Tutorials Introduction JustPy is an object-oriented, component based, high-level Python Web Framework that requires no front-en

927 Jan 08, 2023
A tool for quickly creating REST/HATEOAS/Hypermedia APIs in python

ripozo Ripozo is a tool for building RESTful/HATEOAS/Hypermedia apis. It provides strong, simple, and fully qualified linking between resources, the a

Vertical Knowledge 198 Jan 07, 2023
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
An alternative serializer implementation for REST framework written in cython built for speed.

drf-turbo An alternative serializer implementation for REST framework written in cython built for speed. Free software: MIT license Documentation: htt

Mng 74 Dec 30, 2022
A Simple Kivy Greeting App

SimpleGreetingApp A Simple Kivy Greeting App This is a very simple GUI App that receives a name text input from the user and returns a "Hello" greetin

Mariya 40 Dec 02, 2022
CherryPy is a pythonic, object-oriented HTTP framework. https://docs.cherrypy.org/

Welcome to the GitHub repository of CherryPy! CherryPy is a pythonic, object-oriented HTTP framework. It allows building web applications in much the

CherryPy 1.6k Dec 29, 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 02, 2022
Django Ninja - Fast Django REST Framework

Django Ninja is a web framework for building APIs with Django and Python 3.6+ type hints.

Vitaliy Kucheryaviy 3.8k Jan 02, 2023
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
Dockerized web application on Starlite, SQLAlchemy1.4, PostgreSQL

Production-ready dockerized async REST API on Starlite with SQLAlchemy and PostgreSQL

Artur Shiriev 10 Jan 03, 2023
Serverless Python

Zappa - Serverless Python About Installation and Configuration Running the Initial Setup / Settings Basic Usage Initial Deployments Updates Rollback S

Rich Jones 11.9k Jan 01, 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
The core of a service layer that integrates with the Pyramid Web Framework.

pyramid_services The core of a service layer that integrates with the Pyramid Web Framework. pyramid_services defines a pattern and helper methods for

Michael Merickel 78 Apr 15, 2022