Coder Social home page Coder Social logo

fastcash's Introduction

FastCash Project

This repository contains the FastCash web api code for the course PythonBiellaGroup FastAPI nights.

This project contains an example of FastAPI Projects built during the course.

Install and configure the project

First of all it's important to install poetry.
If you don't know how to install it please follow this guide

If you want to save the virtualenv inside the project folder please do:

Then you have to initialize the project with: poetry install

VSCode settings

To configure and use vscode as main IDE with Python it's important to create two main files: settings.json and launch.json.

Setting the Vscode Ide

This settings can be done only the first time because if you log-in with your Github or Microsoft account it's possible to keep all your settings in every machine and vscode you use.

Please remember to install the required extensions for vscode before.

First of all it's important to create inside the project a folder called: .vscode.

Inside this folder create new file with the name: launch.json. This file it's important because contains all the settings for the vscode python debugger.

The content of the file is this one (paste inside the file).

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
      {
        "name": "Python: Current File",
        "type": "python",
        "request": "launch",
        "program": "${file}",
        "console": "integratedTerminal",
        "cwd": "${workspaceFolder}",
        "env": {
          "PYTHONPATH": "${cwd}",
          "VERBOSITY": "DEBUG",
          
        }
      },
      {
        "name": "FastAPI",
        "type": "python",
        "request": "launch",
        "module": "main",
        "env": {
            "PYTHONPATH": "${cwd}/live",
            "API_ENDPOINT_PORT": "8000",
            "API_ENDPOINT_HOST": "127.0.0.1",
            "VERBOSITY": "DEBUG"
        }
      }
    ]
  }

With the Python: Current File you can launch the debugger on a single python file and with Flask Backend you can launch the flask application with the VSCode debugger directly (in Debug mode of course)

Then you have to create another file inside the .vscode folder in your project, this file is called: settings.json. The file contains all the python settings and information for the project and the ide.

After you have created the file and installed the project with poetry launch: poetry show -v, then copy the first path of your virtualenv.

Now paste this settings inside the new settings.json file.

{
    "python.pythonPath": "<path of your local virtualenv>/bin/python",
    "python.linting.flake8Enabled": true,
    "python.linting.mypyEnabled": false,
    "python.linting.enabled": true
}

Substitute <path of your local virtualenv> with the path copied from poetry show -v command.

After this reload vscode and every time you open a new windows vscode automatically activate the venv created with poetry for you.

Configure the linter with Python

Configure the automatic save with Python

Usefull dev extensions

  • Python (with Pylance):
  • Jupyter:
  • Docker:
  • Todo Tree:
  • Remote development:
  • Live share:
  • docks-markdown:
  • docks-preview:
  • Git History:
  • Git Lens:
  • indent-rainbow:
  • Prettier - Code formatter

Launch and debug (development mode)

Instructions to launch and debug the project locally with vscode.

  1. Clone the project
  2. Install vscode + poetry (if you don't know to install poetry check this guide)
  3. Set vscode (and vscode related files for debugging and venv) with the instructions in this readme file
  4. Install the dependencies of the project with poetry by doing: poetry install
  5. If you want to activate the venv created with poetry in your terminal do: poetry shell
  6. After all the configurations restart vscode, then vscode will update your default IDE virtual env by default (if all the configurations are correct)
  7. You can use the vscode debugger to launch the application or to launch a single python script file

The environment variabile called DEBUG_MODE should be False if you want to test the app via gunicorn. If the environment variable is True you should use the Debug function of VS Code.

If you experience some changes to the pyproject.toml file, you can update your local version of the libraries and environment by running the command: poetry update

If you want you can use also the shell script: launch-debug.sh to test the project in debug mode with Flask and without gunicorn

Test the project

Launch in production mode

First of all check if you have all the tools installed correctly on your machine.

If you want to launch the code (flask backend) in production mode with gunicorn you can use the launch.sh script located inside the main folder.

Remember to set the permissions of the script: sudo chmod +x launch.sh Launch with: ./launch.sh

If you get the error: gunicorn: not found you need to activate the poetry env by doing: poetry shell

You can also launch the single docker compose if you want to test the code inside the docker container by doing docker-compose up --build -d

Considerations and know issues

To use the system with psycopg2 for the postgres database connection it's important to install in your system (linux-based) the requirements: sudo apt-get install libpq-dev

To launch the project from terminal if you are on the project root you have to do: PYTHONPATH="./" python ./test/<name of the script>.py

Be carefull not to install virtualenv via apt on linux, but use virtualenv by pip.

Useful commands

If you want to restore docker on your machine:

docker system prune --all

fastcash's People

Contributors

biancini avatar jeydi avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.