Package: pyrin
PyrinA rich, fast, performant and easy to use application framework
to build apps using Flask on top of it.Pyrin is an application framework built on top of Flask micro-framework to make
life easier for developers who want to develop an enterprise application
using Flask, without having to make their own core layer and getting better code
design and structure that is more maintainable.Pyrin could be used as the parent package of an application, so other application
packages will use its functionality and features to maintain their goals without
worrying about basic implementations.
It is also possible for application packages to extend existing Pyrin packages.Pyrin point of view is to build an application which is more decoupled, so making it
possible to have customized implementations of different packages and also making it
easier to write unit-test packages.Another major fact of Pyrin is to avoid centralized locations for application features, so a team
of multiple developers be able to work on the same repository without facing conflicts here
and there. Also reducing the chances of annoying bugs due to forgetting to register
something in somewhere.InstallingInstall using pip:pip install pyrinRunning TestsTo be able to run tests:Pyrin tests are developed using pytest, you should first
install pyrin tests dependencies using pip:pip install pyrin[tests]Now you could executepython3 start_unit.pyto start all unit tests.Demo ApplicationA demo application developed using Pyrin framework is available at:Pyrin-DemoContribute In Pyrin DevelopmentWe highly appreciate any kind of contributions to Pyrin development.
Fork Pyrin and implement a new feature and make a pull request, we'll let
you know when your work becomes a part of Pyrin.
So, open the project in your IDE and create your pipenv environment.
Then you could start developing Pyrin.Extremely Simple Usage ExampleThe 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 pyrinApplicationclass 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 subclassedApplication, in this example we put it inside the project's main
package, inside__init__.py.Sample Project Structure:root_dirdemo__init__.pyapi.pymodels.pystart.py__init__.py:frompyrin.application.baseimportApplicationclassDemoApplication(Application):passmodels.py:frompyrin.database.model.declarativeimportCoreEntityfrompyrin.database.orm.sql.schema.columnsimportGUIDPKColumn,StringColumn,SmallIntegerColumnclassGuestEntity(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:frompyrin.api.router.decoratorsimportapifrompyrin.core.structsimportDTOfrompyrin.database.servicesimportget_current_storefromdemo.modelsimportGuestEntity@api('/introduce/<name>',authenticated=False)defintroduce(name,**options):"""introduce yourself to us.---parameters:- name: nametype: stringdescription: your nameresponses:200:schema:type: stringdescription: 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)defguests(**options):"""gets the list of all guests.---responses:200:schema:type: arrayitems:type: objectproperties:id:type: stringformat: uuiddescription: id of guestname:type: stringdescription: name of guestage:type: integerdescription: age of guest."""store=get_current_store()returnstore.query(GuestEntity).all()@api('/',authenticated=False)defhello(**options):"""shows the welcome message.---responses:200:schema:properties:message:type: stringdescription: welcome messagecurrent_guests:type: integerdescription: 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)returnresultstart.py:fromdemoimportDemoApplicationif__name__=='__main__':app=DemoApplication()app.run(use_reloader=False)Now you could start application by executing this command in your terminal:python3 start.pyApplication will be available at127.0.0.1:5000by default.Pyrin on default configurations, will use anin-memory sqlitedatabase.Creating a New Pyrin ProjectPyrin 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:pyrinprojectafter 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 ToolAfter creating a new project usingpyrin projectcommand, acli.pyfile 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--helpoption to see all available commands of each group.Builtin Commands:python cli.py alembicpython cli.py babelpython cli.py templatepython cli.py securityIntegration Commands:python cli.py celeryIntegrationsPyrin 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, opensettings/packaging.inifile
and removepyrin.task_queues.celeryfrom theignored_packageslist.Sentry:pip install pyrin[sentry]To enable sentry after installing its dependencies, opensettings/packaging.inifile
and removepyrin.logging.sentryfrom theignored_packageslist.Redis:pip install pyrin[redis]To enable redis after installing its dependencies, opensettings/packaging.inifile
and removepyrin.caching.remote.handlers.redisfrom theignored_moduleslist.Memcached:pip install pyrin[memcached]To enable memcached after installing its dependencies, opensettings/packaging.inifile
and removepyrin.caching.remote.handlers.memcachedfrom theignored_moduleslist.Built-in Swagger UI SupportPyrin has built-in support for Swagger UI thanks toFlasgger.
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 goodyamldocstring for your api method views.
You can head over to127.0.0.1:5000/swaggerto test the Swagger UI.InspirationThis project is inspired by the awesomeDeltapyframework by:@abisxir@mvavesalUnfortunately I couldn't find any links to it online.HintPyrinis a greek word and means core.