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
O SnakeG é um WSGI feito para suprir necessidadades de perfomance e segurança.

SnakeG O SnakeG é um WSGI feito para suprir necessidadades de perfomance e segurança. Veja o que o SnakeG possui: Multiprocessamento de requisições HT

Jaedson Silva 1 Jul 02, 2022
Flask like web framework for AWS Lambda

lambdarest Python routing mini-framework for AWS Lambda with optional JSON-schema validation. ⚠️ A user study is currently happening here, and your op

sloev / Johannes Valbjørn 91 Nov 10, 2022
The source code to the Midnight project

MidnightSniper Started: 24/08/2021 Ended: 24/10/2021 What? This is the source code to a project developed to snipe minecraft names Why release? The ad

Kami 2 Dec 03, 2021
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
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
WebSocket and WAMP in Python for Twisted and asyncio

Autobahn|Python WebSocket & WAMP for Python on Twisted and asyncio. Quick Links: Source Code - Documentation - WebSocket Examples - WAMP Examples Comm

Crossbar.io 2.4k Jan 06, 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
Light, Flexible and Extensible ASGI API framework

Starlite Starlite is a light, opinionated and flexible ASGI API framework built on top of pydantic and Starlette. Check out the Starlite documentation

Na'aman Hirschfeld 1.6k Jan 09, 2023
A library that makes consuming a RESTful API easier and more convenient

Slumber is a Python library that provides a convenient yet powerful object-oriented interface to ReSTful APIs. It acts as a wrapper around the excellent requests library and abstracts away the handli

Sam Giles 597 Dec 13, 2022
An easy-to-use high-performance asynchronous web framework.

中文 | English 一个易用的高性能异步 web 框架。 Index.py 文档 Index.py 实现了 ASGI3 接口,并使用 Radix Tree 进行路由查找。是最快的 Python web 框架之一。一切特性都服务于快速开发高性能的 Web 服务。 大量正确的类型注释 灵活且高效的

Index.py 264 Dec 31, 2022
Screaming-fast Python 3.5+ HTTP toolkit integrated with pipelining HTTP server based on uvloop and picohttpparser.

Japronto! There is no new project development happening at the moment, but it's not abandoned either. Pull requests and new maintainers are welcome. I

Paweł Piotr Przeradowski 8.6k Dec 29, 2022
Containers And REST APIs Workshop

Containers & REST APIs Workshop Containers vs Virtual Machines Ferramentas Podman: https://podman.io/ Docker: https://www.docker.com/ IBM CLI: https:/

Vanderlei Munhoz 8 Dec 16, 2021
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
🔥 Fire up your API with this flamethrower

🔥 Fire up your API. Documentation: https://flama.perdy.io Flama Flama aims to bring a layer on top of Starlette to provide an easy to learn and fast

José Antonio Perdiguero 216 Dec 26, 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 08, 2021
A beginners course for Django

The Definitive Django Learning Platform. Getting started with Django This is the code from the course "Getting Started With Django", found on YouTube

JustDjango 288 Jan 08, 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
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
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
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

2k Dec 31, 2022