Archives de l’auteur : davidhxxx

Flask Rest json with Marshmallow

Models Person from dataclasses import dataclass from typing import List   from flask_example import db from models.Address import Address     @dataclass class Person(db.Model): id: int = db.Column(db.Integer, primary_key=True) firstname: str = db.Column(db.String) lastname = db.Column(db.String) addresses = db.relationship(’Address’, back_populates=’person’, … Continuer la lecture

Publié dans Non classé | Laisser un commentaire

Flask-SQLAlchemy

Set up flask with SQLAlchemy Integrates SQLAlchemy with Flask from flask import Flask from flask_sqlalchemy import SQLAlchemy   app: Flask = Flask(__name__) db: SQLAlchemy = SQLAlchemy() # The import of MySQLAlchemyConfiguration must be after the initialization of db (SQLAlchemy instance) … Continuer la lecture

Publié dans Non classé | Laisser un commentaire

Flask: common problems

Common SQLAlchemy/marshmallow problems Problem: Object initialization order issue. In python and still more to in flask, the order of import and instantiation of python files and classes matters. To make it consistent, we need to be very careful. We can … Continuer la lecture

Publié dans Non classé | Laisser un commentaire

Flask general

Start the application Start the application which the python file is flask_example.py and run it on the port 5001 with the debug options: flask –app flask_example run –port 5001 –debug Routes List all routes mapping: Suppose your flask application file … Continuer la lecture

Publié dans Non classé | Laisser un commentaire

Python install modules

Problem: During a module install, error such as: ERROR: Could not build wheels for pyaudio which use PEP 517 and cannot be installed directly Exception information: Traceback (most recent call last): File "/home/david/whisper_real_time/venv/lib/python3.9/site-packages/pip/_internal/cli/base_command.py", line 186, in _main status = self.run(options, … Continuer la lecture

Publié dans Non classé | Laisser un commentaire

github action workflow examples

Java and docker compose example with a reusable workflow Reusable test execution workflow Key points: – reusable workflow – specify expression – set specific permissions for the job – specify input parameter for actions – Upload an artifact – specify … Continuer la lecture

Publié dans Non classé | Laisser un commentaire

github actions general

General Workflows – it runs one or more jobs. – it is defined by a YAML file located in to your github repository and will run when triggered by an event in your repository, or they can be triggered manually, … Continuer la lecture

Publié dans Non classé | Laisser un commentaire

Analyse memory in Python

Main metrics – identify python file/functions consuming most memory:It is very reliable to detect rise/peak memory. Generally it is computed by a comparison of the process rss of before and after the execution of python code/function. – Number of objects … Continuer la lecture

Publié dans Non classé | Laisser un commentaire

inspect in python

How to check if an object start with a specific package: module = inspect.getmodule(o) is_foo_app: bool = False if module and module.__name__: if module.__name__.split(’.’)[0] == "foo_app": is_foo_app = True Retrieve all members of an object: getmembers: list[tuple[str, Any]] = inspect.getmembers(foo_object) … Continuer la lecture

Publié dans Non classé | Laisser un commentaire

Python: module with submodules

Run a program containing submodules Assume we have the following layout: – module_with_sub_module: the directory that contains the application(It is not the base module directory but a directory that holds it ). – foo/app: a submodule – foo/business: a submodule … Continuer la lecture

Publié dans Non classé | Laisser un commentaire