Git Product home page Git Product logo

cm-training-python301's Introduction

Python 301

In this exercise, you will implement a calculator API that serves endpoints for mathematical functions using FastAPI. The goal is to make you familiar with building APIs, poetry for package and dependency management and pytest for testing. You should also make sure that your code is properly formatted using black and isort.

Getting started

  1. Verify if poetry is installed on your machine using poetry --version.
  2. Clone this repository
  3. In a terminal, navigate to the project's root folder
  4. Use poetry to generate a new package called math_api. Refer to the documentation of the poetry new command to find out how to do that. This will generate the following project structure:
    .
    ├── math_api
    │   ├── README.md
    │   ├── math_api
    │   │   └── __init__.py
    │   ├── pyproject.toml
    │   └── tests
    │       └── __init__.py
    

Exercise

  1. Create a FastAPI app in math_api/app.py (so on the level of pyproject.toml) that serves your FastAPI API. The logic of your app should exist in math_api/math_api/. See FastAPI's 'first steps' documentation to help you to get started. Manage your dependencies with poetry so that teammates could easily set up their own environments. Also try to make a distinction between dependencies for development and dependencies for code that runs in production.
  2. Implement the following endpoints:
    • /add which accepts two parameters a and b and returns the result of a+b
    • /sub which accepts two parameters a and b and returns the result of a-b
    • /mul which accepts two parameters a and b and returns the result of a*b
    • /div which accepts two parameters a and b and returns the result of a/b
    • /fib which accepts a parameter n and returns Fibonacci number $F_n$
  3. During development, pay attention to your project structure and add type hints for your methods and parameters.
  4. Document your code with docstrings.
  5. Write tests for each method with pytest
  6. Format your code with black, isort and flake8.

Extra:

  1. Install pre-commit and configure it so it runs black, flake8, isort and pytest.
  2. Write a shell script that runs your tests and formatting checks, collects the return codes and writes a report to a file.
  3. Package your app with poetry.

cm-training-python301's People

Contributors

bramvandendriessche 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.