Giter Club home page Giter Club logo

inventory-management-api's Introduction

inventory-management-api

Project with Python and PostgreSQL to model an inventory tracking system

FastAPI PostgreSQL SQLAlchemy Docker Ruff

Todo of Features

[ ] IaC to deploy to Production
[ ] Docker Compose File [ ] Change HTTPException details to be more like FastAPI [ ] Update request and response models to be more JSON like - camelCase

Purpose

Design and create a REST API using FastAPI and SQLAlchemy. A quick step into a using an ASGI framework and explore the rich typing system that both projects have made use of.

Code

Environment Management

Currently tool of choice for Python environments is Poetry. This makes it simple to handle version pinning and even packaging as needed.

# Get started by installing a virtual env
poetry install
# Activate venv
poetry shell
# or use the venv Python without activation
poetry run python ...

Semantic Versioning

To keep a single source of truth about the version, instead of using pyproject.toml the semver is stored in inven_api/__init__.py and I use Tiangolo's Poetry Plugin to load the version from there.

Format and Lint

Black has been a great formatter for all of my projects and this one is no different. Ruff has been a great addition to Python projects, yet again showing a great integration of Python and Rust.

These are run on the code in this project using pre-commit. To enforce that usage:

# Make sure that dependencies have been previously installed
poetry run pre-commit install
poetry run pre-commit run --all-files

Quickstart

Test Locally

Since this does rely on PostgreSQL, it is better to run it as-is using Docker Compose. But you can edit the app to use a SQLite connection string ./inven_api/common/.env.db.

# edit DB connection string
vim ./inven_api/common/.env.db
poetry run uvicorn main:APP

From a Docker Container

docker-compose up --build

Development

Start PostgreSQL container

Instead of using latest which at this time is 16, going to use 15.4 for this project.

Start the Postgres container for dev with:

docker run --name postgres-dev -e POSTGRES_PASSWORD=postgres -p 5432:5432 postgres:15.4

Connect to Postgres via psql

Then once the container is started, we can use psql for any later debugging to test our code executions.

We need to specify localhost in this case, otherwise psql will try to use the default machine socket that isn't present due to the container running.

psql -h localhost -U postgres -W

Initialize the Database Tables

It is better to call the SQLAlchemy Base.metadata.create_all from a seperate script and not tie it to the server start up. I think it makes more sense to have a seperate script to do that.

python3 create_database.py

inventory-management-api's People

Contributors

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