SlideShare a Scribd company logo
BASE3
https://base3.dev
Nikola Milisavljevic
Digital CUBE, Belgrade
What is BASE?
- BASE3 is a Python web framework based on Tornado asynchronous networking library,
developed by Digital Cube team for internal use. It is also available to the open source
community to use and contribute to the project.
- We noticed we needed to write a lot of boilerplate code to start working on our
applications
- Solution: create a BASE framework
- BASE principles:
- Implementation of code reusability for common operations (user management,
registration, email sending, PDF generation)
- Simple to use and get going
- Great for onboarding new programmers (with and without Python experience)
- Scalability and microservices
BASE / main features
- Methods and recipes for making REST API based application
- Bundled Python tools for a seamless start
- Python decorators for code reusability and common functionalities
- Authentication using different identity providers (Google, Facebook…)
- Tool for generating source code templates
- Auto-generation of API specification
- Flexibility in the scale and purpose of the application (small, template driven websites to
complex async microservice application)
- Education
Main goals
- Making of REST APIs with focus on business and underlying logic rather than the tools
themselves
- Reduction of the amount of effort needed to bootstrap
- Microservice organized architecture with common microservices already written and
maintained for current and future projects
- Automatic parameter validation with using Models as the schema
- Test Driven Development
- Use of template engines for simple server-side rendered websites
Common services
- Implementation and maintenance of common microservices to encourage code reuse:
- Users / Authentication
https://github.com/digital-cube/base3service-users.git
- Sending emails
https://github.com/digital-cube/base3service-mailer.git
- PDF generator
- Multitenancy
- Blog
Technologies
- Python 3.x
- tornadoweb (web framework and asynchronous networking library)
- Database:
- Currently implemented PostgreSQL using SQLAlchemy ORM, but also other
popular open source RDBMS will be supported soon
- CRUD implementation in API calls (with the use of Models as types)
- Reduction of the amount of duplicated code for simple CRUD operations
- Redis
- Docker
Implemented decorators
- @route
- decorate Handler class and define route where methods can be reachable
- @api
- decorate a method to process input arguments, fetching models
- @auth
- decorate a method to allow only authorized users to access
Handling input parameters
- Input parameters can be passed through URI or Request Body, both of them are read as
parameters in the Handler class
- With Python typing, we can automatically check and validate parameters
- Currently supported types are str, int, bool, float
- Also any defined database Model can be considered as a type
- For storing Models in Database, use the Model type
- For fetching Models from database use Id attribute of Model
- Parameters can be mandatory or optional
- For optional parameters set the default value for this parameter
- None can be used as default value as well
Models as Types
import base
import models
@base.route("/")
class RegisterUserHandler(base.Base):
@base.api()
async def post(self, user: models.User):
self.orm_session.add(user)
self.orm_session.commit()
return {"id": user.id}, base.http.status.CREATED
if __name__ == "__main__":
base.run()
Models as Types
import base
import models
import lookup.permissions as perm
@base.route("/:id_user")
class SingleUserHandler(base.Base):
@base.auth(permissions=perm.ADMIN)
@base.api()
async def get(self, user: models.User.id):
return {"user": user.serialize()}
if __name__ == "__main__":
base.run()
Handling responses
- Since the main goal of BASE is to build a REST API, default response headers are
application/json, but also any other output can be sent (HTML, text or binary)
- To provide the result, just return an object which can be serialized into JSON (dict, list,
string) and this object will be returned to the caller
- Default status code is HTTP code 200 OK, but any other code can be specified as a
second parameter, for example, if you want to return 201 (Created) write:
- return {“id”: obj.id}, http.status.CREATED
- If the method returns None, or if there is no return statement, the default status code will
be 204 (No Content)
Handling exceptions and errors
- Errors, like any other response, can be sent back using a return statement with one of
4XX response code (NOT_FOUND, UNAUTHORIZED, BAD_REQUEST, …)
- We can throw an exception which will be caught in the @api decorator and immediately
the API call will return an error with an error message and id_message (for translation
purposes)
- These errors cascade all the way back to the initial service in the case of calls requiring
multiple services
Inter Process Communication (IPC)
- Services communicate with each other by using our IPC method
- Complex request chains are handled by cascading requests onto different services
(if needed)
- Allows services to have separation of concerns and communicate between themselves
for sharing data and logic
- In BASE we share business logic and data between services through using REST APIs
of the services themselves
- Currently AsyncHTTP request is the only supported method for IPC, and we are planning
to introduce other methods and ways
Concurrency and bottleneck optimization
- We recommend the use of async/await methods to avoid blocking service by multiple
requests
- BASE supports threading coroutine mechanism which will process API calls in multiple
threads
- External workers using message queuing
- Creating multiple instance of the microservice which is a bottleneck
Testing
- Test Driven Development is one of the key concepts of using this framework
- Services can be tested independently by mocking results from other services
- Services can be tested all together in a single integration test
- For this feature, developer needs to follow additional rules (routes throughout all
services should be unique, as well as class name of handler) and additional
configuration setup, documented in example
Try it (source code)
https://base3.dev/examples/hello_world/hello_world.py
import base
@base.route("/")
class IndexHandler(base.Base):
@base.api()
async def get(self):
return {"message": "Hello World"}
if __name__ == "__main__":
base.run()
Try it (using local python3 installation and venv)
Open browser and visit http://localhost:9000
mkdir base-demo && cd base-demo
python3 -m venv .venv
source .venv/bin/activate
pip install wheel base3
curl https://base3.dev/examples/hello_world/hello_world.py -o hello_world.py
python hello_world.py
Try it (using docker / docker-compose)
mkdir base-demo && cd base-demo
curl https://base3.dev/examples/hello_world/hello_world.py -o hello_world.py
curl https://base3.dev/examples/hello_world/docker-compose.yaml -o docker-compose.yaml
curl https://base3.dev/examples/hello_world/Dockerfile -o Dockerfile
docker-compose up
Open browser and visit http://localhost:9000
Microservice based example (using docker / docker-compose)
git clone https://github.com/digital-cube/base3example-contacts.git
cd base3example-contacts
docker-compose up
Open browser or postman and visit http://localhost:9000
Todo:.. Add more links..
app.sfscon.it
Next steps:
- CLI
- Project configuration
- Managing services
- Creating service from a pre-existing template
- Support for other databases except PostgreSQL
- Write more common services
- Automatic documentation generator
Digital Cube
- We have been in business for 5 years and delivered over 30 projects for clients across Europe and North
America.
- We have collaborated with start-ups, mid-markets, and large enterprises.
- Some of our clients include:
- Telmekom Networks (South Tyrol, Italy), OOB (Denmark), 3DSystem (USA/Switzerland), Serbian
Academy of Sciences and Arts (Serbia)...
-
We employ experienced developers, designers and engineers with the main goal of providing the best
possible products and services
- The experience we have gained has enabled us to offer a wide range of software solutions and services
that meet the needs of our clients
- Our focus is constantly on our clients' business challenges and we provide innovative ideas for them
- Our abundant technical expertise is at their disposal around the clock.
Digital Cube provide services in:
- Advisory:
- Product Design
- Business Process, Optimisation and Analysis
- Engineering:
- Web Application Development
- Mobile Application Development
- Desktop Application Development
- Assurance:
- Software Testing and Quality Assurance
- Technical Support
Contribute:
https://base3.dev
https://pypi.org/project/base3/
https://github.com/digital-cube/BASE
BASE3
https://base3.dev
https://pypi.org/project/base3/
https://github.com/digital-cube/BASE
nikola.milisavljevic@digitalcube.rs
Thank you for listening!

More Related Content

What's hot (20)

PDF
Project Fedena and Why Ruby on Rails - ArvindArvind G S
ThoughtWorks
 
PPT
]po[ Sencha File-Storage Specs
Klaus Hofeditz
 
PDF
Create Home Directories on Storage Using WFA and ServiceNow integration
Rutul Shah
 
PDF
Web server
Touhid Arastu
 
PPTX
Hadoop introduction
Dong Ngoc
 
PPTX
Jsf login logout project
Gagandeep Singh
 
PDF
Introduction to RESTful Webservice
Eftakhairul Islam
 
PPT
Excellent rest using asp.net web api
Maurice De Beijer [MVP]
 
PDF
Drupal - short introduction.
Diana Falkowska
 
PPTX
Application server vs Web Server
Gagandeep Singh
 
PPTX
SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra
Sencha
 
PDF
Advaced training-wso2-esb
Chanaka Fernando
 
PDF
Google App Engine
cloudcampnigeria
 
PPTX
MuleSoft Consuming Soap Web Service - CXF jax-ws-client Module
Vince Soliza
 
PPTX
Web ,app and db server presentation
Parth Godhani
 
PPT
Web servers (l6)
Nanhi Sinha
 
PPTX
Introduction to RESTful Webservices in JAVA
psrpatnaik
 
PPT
Easy rest service using PHP reflection api
Matthieu Aubry
 
PPTX
Web services - A Practical Approach
Madhaiyan Muthu
 
PDF
The content manager loves the tree
Maximilian Berghoff
 
Project Fedena and Why Ruby on Rails - ArvindArvind G S
ThoughtWorks
 
]po[ Sencha File-Storage Specs
Klaus Hofeditz
 
Create Home Directories on Storage Using WFA and ServiceNow integration
Rutul Shah
 
Web server
Touhid Arastu
 
Hadoop introduction
Dong Ngoc
 
Jsf login logout project
Gagandeep Singh
 
Introduction to RESTful Webservice
Eftakhairul Islam
 
Excellent rest using asp.net web api
Maurice De Beijer [MVP]
 
Drupal - short introduction.
Diana Falkowska
 
Application server vs Web Server
Gagandeep Singh
 
SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra
Sencha
 
Advaced training-wso2-esb
Chanaka Fernando
 
Google App Engine
cloudcampnigeria
 
MuleSoft Consuming Soap Web Service - CXF jax-ws-client Module
Vince Soliza
 
Web ,app and db server presentation
Parth Godhani
 
Web servers (l6)
Nanhi Sinha
 
Introduction to RESTful Webservices in JAVA
psrpatnaik
 
Easy rest service using PHP reflection api
Matthieu Aubry
 
Web services - A Practical Approach
Madhaiyan Muthu
 
The content manager loves the tree
Maximilian Berghoff
 

Similar to SFScon 2020 - Nikola Milisavljevic - BASE - Python REST API framework (20)

PPTX
mu.semte.ch - A journey from TenForce's perspective - SEMANTICS2016
Aad Versteden
 
PPTX
Design Summit - RESTful API Overview - John Hardy
ManageIQ
 
PDF
Ruby On Rails Basics
Amit Solanki
 
PDF
Drupal South 2015: Introduction to Web Services. Services in Drupal 8.
TechnocratAu
 
PDF
High quality ap is with api platform
Nelson Kopliku
 
PDF
Code igniter - A brief introduction
Commit University
 
PPTX
The next step from Microsoft - Vnext (Srdjan Poznic)
Geekstone
 
PDF
Semantic technologies in practice - KULeuven 2016
Aad Versteden
 
PPTX
Http and REST APIs.
Rahul Tanwani
 
PPTX
Databasecentricapisonthecloudusingplsqlandnodejscon3153oow2016 160922021655
Getting value from IoT, Integration and Data Analytics
 
PDF
The Moving Code Project - Matthias Müller
Luis_de_Sousa
 
PPTX
Building Your First App with MongoDB
MongoDB
 
PPTX
SharePoint 2013 - What's New
AdventosConsulting
 
PPTX
Codeignitor
Gandhi Ravi
 
PDF
Workshop 16: EmberJS Parte I
Visual Engineering
 
PPTX
EMEA Airheads - Configuring different APIs in Aruba 8.x
Aruba, a Hewlett Packard Enterprise company
 
PDF
2.28.17 Introducing DSpace 7 Webinar Slides
DuraSpace
 
PPTX
muCon 2017 - 12 Factor Serverless Applications
Chris Munns
 
PDF
Hia 1691-using iib-to_support_api_economy
Andrew Coleman
 
PPTX
Nasdanika Foundation Server
Pavel Vlasov
 
mu.semte.ch - A journey from TenForce's perspective - SEMANTICS2016
Aad Versteden
 
Design Summit - RESTful API Overview - John Hardy
ManageIQ
 
Ruby On Rails Basics
Amit Solanki
 
Drupal South 2015: Introduction to Web Services. Services in Drupal 8.
TechnocratAu
 
High quality ap is with api platform
Nelson Kopliku
 
Code igniter - A brief introduction
Commit University
 
The next step from Microsoft - Vnext (Srdjan Poznic)
Geekstone
 
Semantic technologies in practice - KULeuven 2016
Aad Versteden
 
Http and REST APIs.
Rahul Tanwani
 
Databasecentricapisonthecloudusingplsqlandnodejscon3153oow2016 160922021655
Getting value from IoT, Integration and Data Analytics
 
The Moving Code Project - Matthias Müller
Luis_de_Sousa
 
Building Your First App with MongoDB
MongoDB
 
SharePoint 2013 - What's New
AdventosConsulting
 
Codeignitor
Gandhi Ravi
 
Workshop 16: EmberJS Parte I
Visual Engineering
 
EMEA Airheads - Configuring different APIs in Aruba 8.x
Aruba, a Hewlett Packard Enterprise company
 
2.28.17 Introducing DSpace 7 Webinar Slides
DuraSpace
 
muCon 2017 - 12 Factor Serverless Applications
Chris Munns
 
Hia 1691-using iib-to_support_api_economy
Andrew Coleman
 
Nasdanika Foundation Server
Pavel Vlasov
 
Ad

More from South Tyrol Free Software Conference (20)

PDF
SFSCON24 - Marina Latini - 1, 2, 3, Doc Kit!
South Tyrol Free Software Conference
 
PDF
SFSCON24 - Carmen Delgado Ivar Grimstad - Nurturing OpenJDK distribution: Ecl...
South Tyrol Free Software Conference
 
PDF
SFSCON24 - Eduardo Guerra - codEEmoji – Making code more informative with emojis
South Tyrol Free Software Conference
 
PDF
SFSCON24 - Juri Solovjov - How to start contributing and still have fun
South Tyrol Free Software Conference
 
PDF
SFSCON24 - Michal Skipala & Bruno Rossi - Monolith Splitter
South Tyrol Free Software Conference
 
PDF
SFSCON24 - Jorge Melegati - Software Engineering Automation: From early tools...
South Tyrol Free Software Conference
 
PDF
SFSCON24 - Chiara Civardi & Dominika Tasarz Sochacka - The Crucial Role of Op...
South Tyrol Free Software Conference
 
PDF
SFSCON24 - Moritz Mock, Barbara Russo & Jorge Melegati - Can Test Driven Deve...
South Tyrol Free Software Conference
 
PDF
SFSCON24 - Aurelio Buonomo & Christian Zanotti - Apisense – Easily monitor an...
South Tyrol Free Software Conference
 
PDF
SFSCON24 - Giovanni Giannotta & Orneda Lecini - Approaches to Object Detectio...
South Tyrol Free Software Conference
 
PDF
SFSCON24 - Alberto Nicoletti - The SMART Box of AURA Project
South Tyrol Free Software Conference
 
PDF
SFSCON24 - Luca Alloatti - Open-source silicon chips
South Tyrol Free Software Conference
 
PDF
SFSCON24 - Roberto Innocenti - 2025 scenario on OpenISA OpenPower Open Hardwa...
South Tyrol Free Software Conference
 
PDF
SFSCON24 - Juan Rico - Enabling global interoperability among smart devices ...
South Tyrol Free Software Conference
 
PDF
SFSCON24 - Seckin Celik & Davide Serpico - Adoption Determinants of Open Hard...
South Tyrol Free Software Conference
 
PDF
SFSCON24 - Stefan Mutschlechner - Smart Werke Meran - Lorawan Use Cases
South Tyrol Free Software Conference
 
PDF
SFSCON24 - Mattia Pizzirani - Raspberry Pi and Node-RED: Open Source Tools fo...
South Tyrol Free Software Conference
 
PDF
SFSCON24 - Attaullah Buriro - ClapMetrics: Decoding Users Genderand Age Throu...
South Tyrol Free Software Conference
 
PDF
SFSCON24 - Joseph P. De Veaugh Geiss - Opt out? Opt in? Opt Green! Bringing F...
South Tyrol Free Software Conference
 
PDF
SFSCON24 - Fulvio Mastrogiovanni - On the ethical challenges raised by robots...
South Tyrol Free Software Conference
 
SFSCON24 - Marina Latini - 1, 2, 3, Doc Kit!
South Tyrol Free Software Conference
 
SFSCON24 - Carmen Delgado Ivar Grimstad - Nurturing OpenJDK distribution: Ecl...
South Tyrol Free Software Conference
 
SFSCON24 - Eduardo Guerra - codEEmoji – Making code more informative with emojis
South Tyrol Free Software Conference
 
SFSCON24 - Juri Solovjov - How to start contributing and still have fun
South Tyrol Free Software Conference
 
SFSCON24 - Michal Skipala & Bruno Rossi - Monolith Splitter
South Tyrol Free Software Conference
 
SFSCON24 - Jorge Melegati - Software Engineering Automation: From early tools...
South Tyrol Free Software Conference
 
SFSCON24 - Chiara Civardi & Dominika Tasarz Sochacka - The Crucial Role of Op...
South Tyrol Free Software Conference
 
SFSCON24 - Moritz Mock, Barbara Russo & Jorge Melegati - Can Test Driven Deve...
South Tyrol Free Software Conference
 
SFSCON24 - Aurelio Buonomo & Christian Zanotti - Apisense – Easily monitor an...
South Tyrol Free Software Conference
 
SFSCON24 - Giovanni Giannotta & Orneda Lecini - Approaches to Object Detectio...
South Tyrol Free Software Conference
 
SFSCON24 - Alberto Nicoletti - The SMART Box of AURA Project
South Tyrol Free Software Conference
 
SFSCON24 - Luca Alloatti - Open-source silicon chips
South Tyrol Free Software Conference
 
SFSCON24 - Roberto Innocenti - 2025 scenario on OpenISA OpenPower Open Hardwa...
South Tyrol Free Software Conference
 
SFSCON24 - Juan Rico - Enabling global interoperability among smart devices ...
South Tyrol Free Software Conference
 
SFSCON24 - Seckin Celik & Davide Serpico - Adoption Determinants of Open Hard...
South Tyrol Free Software Conference
 
SFSCON24 - Stefan Mutschlechner - Smart Werke Meran - Lorawan Use Cases
South Tyrol Free Software Conference
 
SFSCON24 - Mattia Pizzirani - Raspberry Pi and Node-RED: Open Source Tools fo...
South Tyrol Free Software Conference
 
SFSCON24 - Attaullah Buriro - ClapMetrics: Decoding Users Genderand Age Throu...
South Tyrol Free Software Conference
 
SFSCON24 - Joseph P. De Veaugh Geiss - Opt out? Opt in? Opt Green! Bringing F...
South Tyrol Free Software Conference
 
SFSCON24 - Fulvio Mastrogiovanni - On the ethical challenges raised by robots...
South Tyrol Free Software Conference
 
Ad

Recently uploaded (20)

PDF
Wojciech Ciemski for Top Cyber News MAGAZINE. June 2025
Dr. Ludmila Morozova-Buss
 
PDF
Productivity Management Software | Workstatus
Lovely Baghel
 
PPT
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
PPTX
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
PDF
Building Resilience with Digital Twins : Lessons from Korea
SANGHEE SHIN
 
PPTX
Darren Mills The Migration Modernization Balancing Act: Navigating Risks and...
AWS Chicago
 
PDF
TrustArc Webinar - Data Privacy Trends 2025: Mid-Year Insights & Program Stra...
TrustArc
 
PPTX
Extensions Framework (XaaS) - Enabling Orchestrate Anything
ShapeBlue
 
PPTX
Top Managed Service Providers in Los Angeles
Captain IT
 
PDF
Upgrading to z_OS V2R4 Part 01 of 02.pdf
Flavio787771
 
PDF
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
PDF
Impact of IEEE Computer Society in Advancing Emerging Technologies including ...
Hironori Washizaki
 
PDF
Sustainable and comertially viable mining process.pdf
Avijit Kumar Roy
 
PDF
Smart Air Quality Monitoring with Serrax AQM190 LITE
SERRAX TECHNOLOGIES LLP
 
PDF
Human-centred design in online workplace learning and relationship to engagem...
Tracy Tang
 
PDF
Why Orbit Edge Tech is a Top Next JS Development Company in 2025
mahendraalaska08
 
PDF
Women in Automation Presents: Reinventing Yourself — Bold Career Pivots That ...
DianaGray10
 
PDF
Ampere Offers Energy-Efficient Future For AI And Cloud
ShapeBlue
 
PDF
CloudStack GPU Integration - Rohit Yadav
ShapeBlue
 
PDF
Français Patch Tuesday - Juillet
Ivanti
 
Wojciech Ciemski for Top Cyber News MAGAZINE. June 2025
Dr. Ludmila Morozova-Buss
 
Productivity Management Software | Workstatus
Lovely Baghel
 
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
Building Resilience with Digital Twins : Lessons from Korea
SANGHEE SHIN
 
Darren Mills The Migration Modernization Balancing Act: Navigating Risks and...
AWS Chicago
 
TrustArc Webinar - Data Privacy Trends 2025: Mid-Year Insights & Program Stra...
TrustArc
 
Extensions Framework (XaaS) - Enabling Orchestrate Anything
ShapeBlue
 
Top Managed Service Providers in Los Angeles
Captain IT
 
Upgrading to z_OS V2R4 Part 01 of 02.pdf
Flavio787771
 
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
Impact of IEEE Computer Society in Advancing Emerging Technologies including ...
Hironori Washizaki
 
Sustainable and comertially viable mining process.pdf
Avijit Kumar Roy
 
Smart Air Quality Monitoring with Serrax AQM190 LITE
SERRAX TECHNOLOGIES LLP
 
Human-centred design in online workplace learning and relationship to engagem...
Tracy Tang
 
Why Orbit Edge Tech is a Top Next JS Development Company in 2025
mahendraalaska08
 
Women in Automation Presents: Reinventing Yourself — Bold Career Pivots That ...
DianaGray10
 
Ampere Offers Energy-Efficient Future For AI And Cloud
ShapeBlue
 
CloudStack GPU Integration - Rohit Yadav
ShapeBlue
 
Français Patch Tuesday - Juillet
Ivanti
 

SFScon 2020 - Nikola Milisavljevic - BASE - Python REST API framework

  • 2. What is BASE? - BASE3 is a Python web framework based on Tornado asynchronous networking library, developed by Digital Cube team for internal use. It is also available to the open source community to use and contribute to the project. - We noticed we needed to write a lot of boilerplate code to start working on our applications - Solution: create a BASE framework - BASE principles: - Implementation of code reusability for common operations (user management, registration, email sending, PDF generation) - Simple to use and get going - Great for onboarding new programmers (with and without Python experience) - Scalability and microservices
  • 3. BASE / main features - Methods and recipes for making REST API based application - Bundled Python tools for a seamless start - Python decorators for code reusability and common functionalities - Authentication using different identity providers (Google, Facebook…) - Tool for generating source code templates - Auto-generation of API specification - Flexibility in the scale and purpose of the application (small, template driven websites to complex async microservice application) - Education
  • 4. Main goals - Making of REST APIs with focus on business and underlying logic rather than the tools themselves - Reduction of the amount of effort needed to bootstrap - Microservice organized architecture with common microservices already written and maintained for current and future projects - Automatic parameter validation with using Models as the schema - Test Driven Development - Use of template engines for simple server-side rendered websites
  • 5. Common services - Implementation and maintenance of common microservices to encourage code reuse: - Users / Authentication https://github.com/digital-cube/base3service-users.git - Sending emails https://github.com/digital-cube/base3service-mailer.git - PDF generator - Multitenancy - Blog
  • 6. Technologies - Python 3.x - tornadoweb (web framework and asynchronous networking library) - Database: - Currently implemented PostgreSQL using SQLAlchemy ORM, but also other popular open source RDBMS will be supported soon - CRUD implementation in API calls (with the use of Models as types) - Reduction of the amount of duplicated code for simple CRUD operations - Redis - Docker
  • 7. Implemented decorators - @route - decorate Handler class and define route where methods can be reachable - @api - decorate a method to process input arguments, fetching models - @auth - decorate a method to allow only authorized users to access
  • 8. Handling input parameters - Input parameters can be passed through URI or Request Body, both of them are read as parameters in the Handler class - With Python typing, we can automatically check and validate parameters - Currently supported types are str, int, bool, float - Also any defined database Model can be considered as a type - For storing Models in Database, use the Model type - For fetching Models from database use Id attribute of Model - Parameters can be mandatory or optional - For optional parameters set the default value for this parameter - None can be used as default value as well
  • 9. Models as Types import base import models @base.route("/") class RegisterUserHandler(base.Base): @base.api() async def post(self, user: models.User): self.orm_session.add(user) self.orm_session.commit() return {"id": user.id}, base.http.status.CREATED if __name__ == "__main__": base.run()
  • 10. Models as Types import base import models import lookup.permissions as perm @base.route("/:id_user") class SingleUserHandler(base.Base): @base.auth(permissions=perm.ADMIN) @base.api() async def get(self, user: models.User.id): return {"user": user.serialize()} if __name__ == "__main__": base.run()
  • 11. Handling responses - Since the main goal of BASE is to build a REST API, default response headers are application/json, but also any other output can be sent (HTML, text or binary) - To provide the result, just return an object which can be serialized into JSON (dict, list, string) and this object will be returned to the caller - Default status code is HTTP code 200 OK, but any other code can be specified as a second parameter, for example, if you want to return 201 (Created) write: - return {“id”: obj.id}, http.status.CREATED - If the method returns None, or if there is no return statement, the default status code will be 204 (No Content)
  • 12. Handling exceptions and errors - Errors, like any other response, can be sent back using a return statement with one of 4XX response code (NOT_FOUND, UNAUTHORIZED, BAD_REQUEST, …) - We can throw an exception which will be caught in the @api decorator and immediately the API call will return an error with an error message and id_message (for translation purposes) - These errors cascade all the way back to the initial service in the case of calls requiring multiple services
  • 13. Inter Process Communication (IPC) - Services communicate with each other by using our IPC method - Complex request chains are handled by cascading requests onto different services (if needed) - Allows services to have separation of concerns and communicate between themselves for sharing data and logic - In BASE we share business logic and data between services through using REST APIs of the services themselves - Currently AsyncHTTP request is the only supported method for IPC, and we are planning to introduce other methods and ways
  • 14. Concurrency and bottleneck optimization - We recommend the use of async/await methods to avoid blocking service by multiple requests - BASE supports threading coroutine mechanism which will process API calls in multiple threads - External workers using message queuing - Creating multiple instance of the microservice which is a bottleneck
  • 15. Testing - Test Driven Development is one of the key concepts of using this framework - Services can be tested independently by mocking results from other services - Services can be tested all together in a single integration test - For this feature, developer needs to follow additional rules (routes throughout all services should be unique, as well as class name of handler) and additional configuration setup, documented in example
  • 16. Try it (source code) https://base3.dev/examples/hello_world/hello_world.py import base @base.route("/") class IndexHandler(base.Base): @base.api() async def get(self): return {"message": "Hello World"} if __name__ == "__main__": base.run()
  • 17. Try it (using local python3 installation and venv) Open browser and visit http://localhost:9000 mkdir base-demo && cd base-demo python3 -m venv .venv source .venv/bin/activate pip install wheel base3 curl https://base3.dev/examples/hello_world/hello_world.py -o hello_world.py python hello_world.py
  • 18. Try it (using docker / docker-compose) mkdir base-demo && cd base-demo curl https://base3.dev/examples/hello_world/hello_world.py -o hello_world.py curl https://base3.dev/examples/hello_world/docker-compose.yaml -o docker-compose.yaml curl https://base3.dev/examples/hello_world/Dockerfile -o Dockerfile docker-compose up Open browser and visit http://localhost:9000
  • 19. Microservice based example (using docker / docker-compose) git clone https://github.com/digital-cube/base3example-contacts.git cd base3example-contacts docker-compose up Open browser or postman and visit http://localhost:9000 Todo:.. Add more links..
  • 21. Next steps: - CLI - Project configuration - Managing services - Creating service from a pre-existing template - Support for other databases except PostgreSQL - Write more common services - Automatic documentation generator
  • 22. Digital Cube - We have been in business for 5 years and delivered over 30 projects for clients across Europe and North America. - We have collaborated with start-ups, mid-markets, and large enterprises. - Some of our clients include: - Telmekom Networks (South Tyrol, Italy), OOB (Denmark), 3DSystem (USA/Switzerland), Serbian Academy of Sciences and Arts (Serbia)... - We employ experienced developers, designers and engineers with the main goal of providing the best possible products and services - The experience we have gained has enabled us to offer a wide range of software solutions and services that meet the needs of our clients - Our focus is constantly on our clients' business challenges and we provide innovative ideas for them - Our abundant technical expertise is at their disposal around the clock.
  • 23. Digital Cube provide services in: - Advisory: - Product Design - Business Process, Optimisation and Analysis - Engineering: - Web Application Development - Mobile Application Development - Desktop Application Development - Assurance: - Software Testing and Quality Assurance - Technical Support