Code Monkey home page Code Monkey logo

fastapi-sqlmodel's Introduction

alt text

FastAPI + SQLModel Boilerplate App

A RestAPI real world app based on SQLModel documentation example, using FastAPI and SQLModel

Quickstart

  1. Start the App:
  • Using Python: pipenv run python asgi.py

  • sing Docker: docker build -t sqlmodel-api:latest . && docker run -p 8080:8080 sqlmodel-api:latest

  1. Use Openapi at: http://localhost:8080/#/

Running Tests:

While your app is running, open another terminal: pytest -v tavern_tests/

alt text

fastapi-sqlmodel's People

Contributors

22degrees avatar anthonycepeda avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

fastapi-sqlmodel's Issues

A question for the overall structure

A newbie here! Why do we put the functions for accessing data into the crud file and later call it in view files, usually I get answers like "to increase security" for this kind of question, but no one is able to explain it, can you please answer that. Thank you.

Many to Many Models

I love how you structured this. Would it be possible to add an example of many to many models? I'm having a difficult time getting them to work with your structure. The issue here is if you had a many to many model with heroes (going off the example from the SQL Model docs) you'd need to make a link table in the public/hero/models.py file. But what would the HeroCreate model look like? And what additional routes would you add in the routes.py file? Thank you so much!

Problem creating database and tables with "starup" event with fastapi and sqlmodel

Hi man, I'm working with fastapi and sqlmodel to develop a rest api.
Observing your way of working I see that to create the database you have to execute the created_db.py module.
Looking at the official sqlmodel page they propose to create the database and tables using the "starup" event provided by fastapi.
(attached link https://sqlmodel.tiangolo.com/tutorial/fastapi/simple-hero-api/#create-database-and-tables-on-startup)
In this way, when executing the app with the command "uvicoirn main:app --reload" the database and tables are immediately created.
I tried to do it, but it generates an error, precisely because of the "starup" event. The shell tells me that this event (which apparently comes from starlette) needs other arguments.
I appreciate any help.
Captura desde 2023-01-24 11-29-51
Captura desde 2023-01-24 11-36-33

Typo in on_startup()?

I believe the function is not called here?

 @app.on_event("startup")
    def on_starup():
        create_db_and_tables  # should be create_db_and_tables()

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.