Exploring Python🐍 and Frameworks: My Experiences in Software Architecture
Published: 2024-01-08 18:46:53

*Introduction:*
I began my journey into programming languages in 2009 while studying at the university. I learned programming logic with Pascal, data structures with C, and object-oriented programming with C++ and Java. It wasn’t until 2013 that I discovered Python, and I was immediately drawn to its practicality, low verbosity, and wide range of applications. Python offered me the flexibility to work with embedded systems like Raspberry Pi, develop web applications using Flask or Django, and easily write automation scripts. In this article, I will share my experiences working with different software architectures using Python.

“It’s not just Python, it’s programming that’s fun.” — Guido van Rossum

First Experience with Embedded Python: After discovering Python, I delved into its applications for embedded projects using Raspberry Pi. I started teaching Python workshops at the university and began developing personal projects using Python and Raspberry Pi. In 2017, while pursuing my master’s degree, I had the opportunity to apply my knowledge in an industrial setting. I collaborated with the director of a local lock manufacturing company on a production item counting project, which I documented in an article titled “Unlocking the Potential of Industry IoT: A Journey of Intelligent Production.”

“The Internet of Things (IoT) is about connecting everyday objects to the internet and enabling them to send and receive data.” — Kevin Ashton

*Web Projects:*
Over the years, I worked on several projects utilizing Python, specifically with the Flask and Django frameworks. These projects spanned various domains, and I will briefly discuss the architecture of each, always emphasizing the use of Python.

1.*Media Management and Distribution System:*

In a project involving the management and distribution of digital media, such as music and video content for platforms like YouTube, I detailed my experience in an article titled “Building a Media Management and Distribution System with Serverless Architecture.” The project leveraged Python in a serverless architecture using AWS resources, including Lambda Functions.

“Serverless architecture provides developers with a way to abstract infrastructure management tasks and focus solely on writing code.” — Martin Fowler

Example code snippet using Flask:

 ```from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello():
    return 'Hello, world!'
if __name__ == '__main__':
    app.run() ```

*2. Geoprocessing System:*
Another project focused on a geoprocessing platform designed to handle and process geographical mapping data captured by drones or satellites. The system allowed users to register mapping routines for specific regions, process the captured images, and generate high-precision maps with different layers, such as soil temperature data. We used Python with Flask as a REST API, employed authentication with JWT, utilized a Postgres database, and containerized the application using Docker.

“Geoprocessing involves the collection, management, analysis, and display of spatially referenced data.” — Michael Law and Amy Collins

Example code snippet using Flask and Fiona:

 ```from flask import Flask
import fiona
app = Flask(__name__)
@app.route('/')
def process_geospatial_data():
    # Process geospatial data using Fiona
    ...
if __name__ == '__main__':
    app.run() ```

Arquitechture:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0bjk04uom1beskweircl.png)
*3. HealthTech Marketplace — Physical Education:*

In this project, I developed a marketplace platform that connected physical education professionals with individuals seeking online services. Python, Flask, and Postgres were the primary technologies used. Continuous deployment was achieved through GitLab CI/CD pipelines, and we integrated Okta for authentication, Pillow for image processing, PyJWT for web token management, and Pytest for automated unit testing.

“Technology can revolutionize the field of health and fitness by making personalized care and services accessible to everyone.” — Anne Wojcicki

Example code snippet using SQLAlchemy:

 ```from flask import Flask
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://user:password@localhost/mydatabase'
db = SQLAlchemy(app)
class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50))
if __name__ == '__main__':
    app.run() ```

Arquitechture:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i8b3gxh2jjfntmihgl0f.png)
*4. HealthTech Marketplace — Sleep Care:*

This project focused on sleep care and created a marketplace for connecting medical professionals specializing in sleep-related issues with patients. The system allowed doctors to register patients and access dashboards containing sleep data collected via forms, mobile apps, or IoT devices. Python, Django, AWS Lambda, RDS Aurora, and other technologies were employed.

“Technology can significantly impact sleep research and facilitate improved sleep health outcomes.” — Conor Heneghan

Example code snippet using Django and Firebase:

 ```from django.shortcuts import render
from firebase_admin import auth
def register_user(request):
    # User registration logic using Firebase authentication
    ...
def analyze_sleep_data(request):
    # Analyze sleep data stored in Firebase Firestore
    ...
def display_dashboard(request):
    # Render dashboard template with sleep-related data
    ... ```
Arquitechture:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/axdnw60b1cpcw1p15nph.png)
*5. Open Innovation Management:*

This project focused on open innovation management, providing a platform for companies to post challenges and independent groups or universities to submit projects to solve these challenges. Python and Django were used for the back-end, with Celery for asynchronous task management. Other technologies included DataDog for monitoring, Bitbucket for CI/CD integration, and Firebase for authentication and data storage.

“Open innovation allows companies to leverage external ideas and technologies to drive internal innovation.” — Henry Chesbrough

Example code snippet using Django and Celery:

 ```from django.shortcuts import render
from celery import shared_task
@shared_task
def process_project_submission(project_id):
    # Process project submission asynchronously
    ...
def review_project(request):
    # Review submitted projects and provide feedback
    ... ```
Arquitechture:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h97y1u20xgoqqilmferc.png)
*6. Questionary Feedback Advertising Platform:*

This application aimed to monitor marketing campaigns through a question-and-answer system. The platform allowed brand owners to configure questionnaires and manage marketing campaigns. Python, CherryPy, MongoDB, and other technologies were utilized, with Docker for containerization, GitHub Actions for CI/CD, and Looker for business intelligence reporting.

“Questionnaires provide valuable insights into customer preferences and opinions, enabling targeted marketing strategies.” — Philip Kotler

Example code snippet using CherryPy:

 ```import cherrypy
class CampaignManager:
    @cherrypy.expose
    def index(self):
        return "Welcome to the Campaign Manager!"
if __name__ == '__main__':
    cherrypy.quickstart(CampaignManager()) ```

Arquitechture:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lvd5d6utrreahu03hvxz.png)
*My Impressions on Python, Frameworks, and Architectures:*
In my experience, Python has proven to be a performant programming language. I prefer utilizing Python’s new type hints to enhance control over attributes, parameters, and method returns. This allows me to explicitly define the design patterns I am implementing. When it comes to frameworks, I tend to favor lightweight options like Flask as they enable the development of decoupled and performant applications. While Django excels in robustness and suits larger corporate projects, it presents challenges when attempting to separate services responsibly following SOLID and DDD principles. I highly value unit testing with Pytest and automated deployment processes.

Python has also proven invaluable for integration testing and scripting alongside other primary languages. In the realm of serverless architectures, Python performs well when used with minimal dependencies and frameworks.

For embedded projects, Python has consistently provided excellent performance, particularly when writing scripts for Raspberry Pi. 🐍🔧🚀