├── .github └── workflows │ └── python-app.yml ├── .gitignore ├── .gitlab-ci.yml ├── LICENSE ├── README.md ├── app ├── alembic.ini ├── alembic │ ├── README │ ├── env.py │ ├── script.py.mako │ └── versions │ │ ├── 7ae7d0980f1f_new_migration.py │ │ └── a5383190faa2_new_migration.py ├── files.py ├── main.py ├── models │ ├── __init__.py │ └── models.py └── schemas │ ├── __init__.py │ └── schema.py └── requirements.txt /.github/workflows/python-app.yml: -------------------------------------------------------------------------------- 1 | # This workflow will install Python dependencies, run tests and lint with a single version of Python 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions 3 | 4 | name: Python application 5 | 6 | on: 7 | push: 8 | branches: [ "main" ] 9 | pull_request: 10 | branches: [ "main" ] 11 | 12 | permissions: 13 | contents: read 14 | 15 | jobs: 16 | build: 17 | 18 | runs-on: ubuntu-latest 19 | 20 | steps: 21 | - uses: actions/checkout@v3 22 | - name: Set up Python 3.10 23 | uses: actions/setup-python@v3 24 | with: 25 | python-version: "3.10" 26 | - name: Install dependencies 27 | run: | 28 | python -m pip install --upgrade pip 29 | pip install flake8 pytest 30 | if [ -f requirements.txt ]; then pip install -r requirements.txt; fi 31 | - name: Lint with flake8 32 | run: | 33 | # stop the build if there are Python syntax errors or undefined names 34 | flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics 35 | # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide 36 | flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics 37 | 38 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ 130 | -------------------------------------------------------------------------------- /.gitlab-ci.yml: -------------------------------------------------------------------------------- 1 | # This workflow will install Python dependencies, run tests and lint with a single version of Python 2 | 3 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions 4 | 5 | name: Python application 6 | 7 | on: 8 | push: 9 | branches: [ "main" ] 10 | pull_request: 11 | branches: [ "main" ] 12 | 13 | permissions: 14 | contents: read 15 | 16 | jobs: 17 | build: 18 | 19 | runs-on: ubuntu-latest 20 | 21 | steps: 22 | - uses: actions/checkout@v3 23 | - name: Set up Python 3.10 24 | uses: actions/setup-python@v3 25 | with: 26 | python-version: "3.10" 27 | - name: Install dependencies 28 | run: | 29 | python -m pip install --upgrade pip 30 | pip install flake8 pytest 31 | if [ -f requirements.txt ]; then pip install -r requirements.txt; fi 32 | - name: Lint with flake8 33 | run: | 34 | # stop the build if there are Python syntax errors or undefined names 35 | flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics 36 | # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide 37 | flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics 38 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Jitendra Meena 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # FastAPI 2 | 3 | FastAPI is a modern, high-performance web framework for building APIs with Python based on standard type hints. It has the following key features: Fast to run: It offers very high performance, on par with NodeJS and Go, thanks to Starlette and pydantic 4 | 5 | 7 | 8 | 9 | # Basic Setup 10 | 11 | 1. Create your virtual environment 12 | 2. Create a project directry 13 | 3. git clone remote url 14 | 15 | # Install Dependencies 16 | ```bash 17 | pip install -r requirements.txt 18 | 19 | Dependencies: 20 | python ≥ 3.5 21 | fastapi 22 | pydantic 23 | fastapi-sqlalchemy 24 | alembic 25 | psycopg2 26 | uvicorn 27 | ``` 28 | 29 | 30 | # Pydantic 31 | pydantic enforces type hints at runtime, and provides user friendly errors when data is invalid. We can define how data should be in pure python and validate it easily with pydantic. 32 | 33 | # ASGI specification 34 | ASGI (Asynchronous Server Gateway Interface) is a spiritual successor to WSGI, intended to provide a standard interface between async-capable Python web servers, frameworks, and applications. 35 | 36 | # Uvicorn server 37 | Uvicorn is a lightning-fast ASGI server, built on uvloop and httptools. 38 | 39 | # Alembic 40 | Alembic is a lightweight database migration tool for usage with the SQLAlchemy Database Toolkit for Python 41 | 42 | 43 | 44 | # DATABASES = 45 | Create an environment file and name it .env. 46 | Inside the .env file, do the following: 47 | 48 | ```bash 49 | DATABASE_URI = 'postgresql://postgres:@localhost/' 50 | ``` 51 | 52 | 53 | 54 | # Migrate Database 55 | It will create a folder called alembic. Inside the folder, go to the env.py file and do the following: 56 | ```bash 57 | alembic init alembic 58 | ``` 59 | 60 | Run the following code to enable migration: 61 | 62 | ```bash 63 | alembic upgrade head 64 | 65 | alembic revision --autogenerate -m "New Migration" 66 | 67 | ``` 68 | 69 | # Run Server: 70 | To kickstart the app, use: 71 | 72 | ```bash 73 | uvicorn main:app --reload 74 | 75 | ``` 76 | 77 | # Jitendra Meena -------------------------------------------------------------------------------- /app/alembic.ini: -------------------------------------------------------------------------------- 1 | # A generic, single database configuration. 2 | 3 | [alembic] 4 | # path to migration scripts 5 | script_location = alembic 6 | 7 | # template used to generate migration files 8 | # file_template = %%(rev)s_%%(slug)s 9 | 10 | # timezone to use when rendering the date 11 | # within the migration file as well as the filename. 12 | # string value is passed to dateutil.tz.gettz() 13 | # leave blank for localtime 14 | # timezone = 15 | 16 | # max length of characters to apply to the 17 | # "slug" field 18 | # truncate_slug_length = 40 19 | 20 | # set to 'true' to run the environment during 21 | # the 'revision' command, regardless of autogenerate 22 | # revision_environment = false 23 | 24 | # set to 'true' to allow .pyc and .pyo files without 25 | # a source .py file to be detected as revisions in the 26 | # versions/ directory 27 | # sourceless = false 28 | 29 | # version location specification; this defaults 30 | # to alembic/versions. When using multiple version 31 | # directories, initial revisions must be specified with --version-path 32 | # version_locations = %(here)s/bar %(here)s/bat alembic/versions 33 | 34 | # the output encoding used when revision files 35 | # are written from script.py.mako 36 | # output_encoding = utf-8 37 | 38 | sqlalchemy.url = postgresql://postgres:postgres@localhost/FastAPIDB 39 | 40 | 41 | # Logging configuration 42 | [loggers] 43 | keys = root,sqlalchemy,alembic 44 | 45 | [handlers] 46 | keys = console 47 | 48 | [formatters] 49 | keys = generic 50 | 51 | [logger_root] 52 | level = WARN 53 | handlers = console 54 | qualname = 55 | 56 | [logger_sqlalchemy] 57 | level = WARN 58 | handlers = 59 | qualname = sqlalchemy.engine 60 | 61 | [logger_alembic] 62 | level = INFO 63 | handlers = 64 | qualname = alembic 65 | 66 | [handler_console] 67 | class = StreamHandler 68 | args = (sys.stderr,) 69 | level = NOTSET 70 | formatter = generic 71 | 72 | [formatter_generic] 73 | format = %(levelname)-5.5s [%(name)s] %(message)s 74 | datefmt = %H:%M:%S 75 | -------------------------------------------------------------------------------- /app/alembic/README: -------------------------------------------------------------------------------- 1 | Generic single-database configuration. -------------------------------------------------------------------------------- /app/alembic/env.py: -------------------------------------------------------------------------------- 1 | from logging.config import fileConfig 2 | 3 | from sqlalchemy import engine_from_config 4 | from sqlalchemy import pool 5 | from models.models import Base 6 | from alembic import context 7 | 8 | # this is the Alembic Config object, which provides 9 | # access to the values within the .ini file in use. 10 | config = context.config 11 | 12 | # Interpret the config file for Python logging. 13 | # This line sets up loggers basically. 14 | fileConfig(config.config_file_name) 15 | 16 | # add your model's MetaData object here 17 | # for 'autogenerate' support 18 | # from myapp import mymodel 19 | # target_metadata = mymodel.Base.metadata 20 | target_metadata = Base.metadata 21 | 22 | # other values from the config, defined by the needs of env.py, 23 | # can be acquired: 24 | # my_important_option = config.get_main_option("my_important_option") 25 | # ... etc. 26 | 27 | 28 | def run_migrations_offline(): 29 | """Run migrations in 'offline' mode. 30 | 31 | This configures the context with just a URL 32 | and not an Engine, though an Engine is acceptable 33 | here as well. By skipping the Engine creation 34 | we don't even need a DBAPI to be available. 35 | 36 | Calls to context.execute() here emit the given string to the 37 | script output. 38 | 39 | """ 40 | url = config.get_main_option("sqlalchemy.url") 41 | context.configure( 42 | url=url, 43 | target_metadata=target_metadata, 44 | literal_binds=True, 45 | dialect_opts={"paramstyle": "named"}, 46 | ) 47 | 48 | with context.begin_transaction(): 49 | context.run_migrations() 50 | 51 | 52 | def run_migrations_online(): 53 | """Run migrations in 'online' mode. 54 | 55 | In this scenario we need to create an Engine 56 | and associate a connection with the context. 57 | 58 | """ 59 | connectable = engine_from_config( 60 | config.get_section(config.config_ini_section), 61 | prefix="sqlalchemy.", 62 | poolclass=pool.NullPool, 63 | ) 64 | 65 | with connectable.connect() as connection: 66 | context.configure( 67 | connection=connection, target_metadata=target_metadata 68 | ) 69 | 70 | with context.begin_transaction(): 71 | context.run_migrations() 72 | 73 | 74 | if context.is_offline_mode(): 75 | run_migrations_offline() 76 | else: 77 | run_migrations_online() 78 | -------------------------------------------------------------------------------- /app/alembic/script.py.mako: -------------------------------------------------------------------------------- 1 | """${message} 2 | 3 | Revision ID: ${up_revision} 4 | Revises: ${down_revision | comma,n} 5 | Create Date: ${create_date} 6 | 7 | """ 8 | from alembic import op 9 | import sqlalchemy as sa 10 | ${imports if imports else ""} 11 | 12 | # revision identifiers, used by Alembic. 13 | revision = ${repr(up_revision)} 14 | down_revision = ${repr(down_revision)} 15 | branch_labels = ${repr(branch_labels)} 16 | depends_on = ${repr(depends_on)} 17 | 18 | 19 | def upgrade(): 20 | ${upgrades if upgrades else "pass"} 21 | 22 | 23 | def downgrade(): 24 | ${downgrades if downgrades else "pass"} 25 | -------------------------------------------------------------------------------- /app/alembic/versions/7ae7d0980f1f_new_migration.py: -------------------------------------------------------------------------------- 1 | """New Migration 2 | 3 | Revision ID: 7ae7d0980f1f 4 | Revises: 5 | Create Date: 2022-06-29 13:47:13.527106 6 | 7 | """ 8 | from alembic import op 9 | import sqlalchemy as sa 10 | 11 | 12 | # revision identifiers, used by Alembic. 13 | revision = '7ae7d0980f1f' 14 | down_revision = None 15 | branch_labels = None 16 | depends_on = None 17 | 18 | 19 | def upgrade(): 20 | # ### commands auto generated by Alembic - please adjust! ### 21 | op.create_table('author', 22 | sa.Column('id', sa.Integer(), nullable=False), 23 | sa.Column('name', sa.String(), nullable=True), 24 | sa.Column('age', sa.Integer(), nullable=True), 25 | sa.Column('time_created', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True), 26 | sa.Column('time_updated', sa.DateTime(timezone=True), nullable=True), 27 | sa.PrimaryKeyConstraint('id') 28 | ) 29 | op.create_table('book', 30 | sa.Column('id', sa.Integer(), nullable=False), 31 | sa.Column('title', sa.String(), nullable=True), 32 | sa.Column('rating', sa.Float(), nullable=True), 33 | sa.Column('time_created', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True), 34 | sa.Column('time_updated', sa.DateTime(timezone=True), nullable=True), 35 | sa.Column('author_id', sa.Integer(), nullable=True), 36 | sa.ForeignKeyConstraint(['author_id'], ['author.id'], ), 37 | sa.PrimaryKeyConstraint('id') 38 | ) 39 | op.create_index(op.f('ix_book_id'), 'book', ['id'], unique=False) 40 | # ### end Alembic commands ### 41 | 42 | 43 | def downgrade(): 44 | # ### commands auto generated by Alembic - please adjust! ### 45 | op.drop_index(op.f('ix_book_id'), table_name='book') 46 | op.drop_table('book') 47 | op.drop_table('author') 48 | # ### end Alembic commands ### 49 | -------------------------------------------------------------------------------- /app/alembic/versions/a5383190faa2_new_migration.py: -------------------------------------------------------------------------------- 1 | """New Migration 2 | 3 | Revision ID: a5383190faa2 4 | Revises: 7ae7d0980f1f 5 | Create Date: 2022-06-29 13:47:47.335861 6 | 7 | """ 8 | from alembic import op 9 | import sqlalchemy as sa 10 | 11 | 12 | # revision identifiers, used by Alembic. 13 | revision = 'a5383190faa2' 14 | down_revision = '7ae7d0980f1f' 15 | branch_labels = None 16 | depends_on = None 17 | 18 | 19 | def upgrade(): 20 | # ### commands auto generated by Alembic - please adjust! ### 21 | pass 22 | # ### end Alembic commands ### 23 | 24 | 25 | def downgrade(): 26 | # ### commands auto generated by Alembic - please adjust! ### 27 | pass 28 | # ### end Alembic commands ### 29 | -------------------------------------------------------------------------------- /app/files.py: -------------------------------------------------------------------------------- 1 | from typing import Union 2 | 3 | from fastapi import FastAPI, status, Form,File, UploadFile 4 | from pydantic import BaseModel, EmailStr 5 | 6 | app = FastAPI() 7 | 8 | 9 | class UserBase(BaseModel): 10 | username: str 11 | email: EmailStr 12 | full_name: Union[str, None] = None 13 | 14 | 15 | class UserIn(UserBase): 16 | password: str 17 | 18 | 19 | class UserOut(UserBase): 20 | pass 21 | 22 | 23 | class UserInDB(UserBase): 24 | hashed_password: str 25 | 26 | 27 | def fake_password_hasher(raw_password: str): 28 | return "supersecret" + raw_password 29 | 30 | 31 | def fake_save_user(user_in: UserIn): 32 | hashed_password = fake_password_hasher(user_in.password) 33 | user_in_db = UserInDB(**user_in.dict(), hashed_password=hashed_password) 34 | print("User saved! ..not really") 35 | return user_in_db 36 | 37 | 38 | @app.post("/user/", response_model=UserOut,status_code=status.HTTP_201_CREATED) 39 | async def create_user(user_in: UserIn): 40 | user_saved = fake_save_user(user_in) 41 | return user_saved 42 | 43 | @app.post("/login/") 44 | async def login(username: str = Form(), password: str = Form()): 45 | return {"username": username} 46 | 47 | """ 48 | File Uploade and get file name details 49 | 50 | """ 51 | 52 | # @app.post("/files/") 53 | # async def create_file(file: bytes = File()): 54 | # return {"file_size": len(file)} 55 | 56 | @app.post("/files/") 57 | async def create_file( 58 | file: bytes = File(), fileb: UploadFile = File(), token: str = Form()): 59 | return { 60 | "file_size": len(file), 61 | "token": token, 62 | "fileb_content_type": fileb.content_type, 63 | } 64 | 65 | @app.post("/uploadfile/") 66 | async def create_upload_file(file: UploadFile): 67 | """ 68 | you can uploadfile: 69 | 70 | - **name**: each file must have a name 71 | - **description**: you can get res. 72 | 73 | """ 74 | return {"filename": file.filename} -------------------------------------------------------------------------------- /app/main.py: -------------------------------------------------------------------------------- 1 | import uvicorn 2 | from fastapi import FastAPI 3 | from fastapi_sqlalchemy import DBSessionMiddleware, db 4 | 5 | from schemas.schema import Book as SchemaBook 6 | from schemas.schema import Author as SchemaAuthor 7 | 8 | from schemas.schema import Book 9 | from schemas.schema import Author 10 | 11 | from models.models import Book as ModelBook 12 | from models.models import Author as ModelAuthor 13 | 14 | import os 15 | from dotenv import load_dotenv 16 | 17 | load_dotenv('.env') 18 | 19 | 20 | app = FastAPI() 21 | 22 | # to avoid csrftokenError 23 | app.add_middleware(DBSessionMiddleware, db_url='postgresql://postgres:postgres@localhost/FastAPIDB') 24 | 25 | @app.get("/") 26 | async def root(): 27 | return {"message": "CICD Implementation"} 28 | 29 | 30 | @app.post('/book/', response_model=SchemaBook) 31 | async def book(book: SchemaBook): 32 | db_book = ModelBook(title=book.title, rating=book.rating, author_id = book.author_id) 33 | db.session.add(db_book) 34 | db.session.commit() 35 | return db_book 36 | 37 | @app.get('/book/') 38 | async def book(): 39 | book = db.session.query(ModelBook).all() 40 | return book 41 | 42 | 43 | 44 | @app.post('/author/', response_model=SchemaAuthor) 45 | async def author(author:SchemaAuthor): 46 | db_author = ModelAuthor(name=author.name, age=author.age) 47 | db.session.add(db_author) 48 | db.session.commit() 49 | return db_author 50 | 51 | @app.get('/author/') 52 | async def author(): 53 | author = db.session.query(ModelAuthor).all() 54 | return author 55 | 56 | 57 | # To run locally 58 | if __name__ == '__main__': 59 | uvicorn.run(app, host='0.0.0.0', port=8000) 60 | -------------------------------------------------------------------------------- /app/models/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jitendra-meena/FastAPI/bddde34d664467bc5bc6b01b45b297f3bc778b24/app/models/__init__.py -------------------------------------------------------------------------------- /app/models/models.py: -------------------------------------------------------------------------------- 1 | from sqlalchemy import Column, DateTime, ForeignKey, Integer, String, Float 2 | from sqlalchemy.ext.declarative import declarative_base 3 | from sqlalchemy.orm import relationship 4 | from sqlalchemy.sql import func 5 | 6 | 7 | Base = declarative_base() 8 | 9 | 10 | 11 | class Book(Base): 12 | __tablename__ = 'book' 13 | id = Column(Integer, primary_key=True, index=True) 14 | title = Column(String) 15 | rating = Column(Float) 16 | time_created = Column(DateTime(timezone=True), server_default=func.now()) 17 | time_updated = Column(DateTime(timezone=True), onupdate=func.now()) 18 | author_id = Column(Integer, ForeignKey('author.id')) 19 | 20 | author = relationship('Author') 21 | 22 | 23 | class Author(Base): 24 | __tablename__ = 'author' 25 | id = Column(Integer, primary_key=True) 26 | name = Column(String) 27 | age = Column(Integer) 28 | time_created = Column(DateTime(timezone=True), server_default=func.now()) 29 | time_updated = Column(DateTime(timezone=True), onupdate=func.now()) 30 | 31 | -------------------------------------------------------------------------------- /app/schemas/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jitendra-meena/FastAPI/bddde34d664467bc5bc6b01b45b297f3bc778b24/app/schemas/__init__.py -------------------------------------------------------------------------------- /app/schemas/schema.py: -------------------------------------------------------------------------------- 1 | # build a schema using pydantic 2 | from pydantic import BaseModel 3 | 4 | class Book(BaseModel): 5 | title: str 6 | rating: int 7 | author_id: int 8 | 9 | class Config: 10 | orm_mode = True 11 | 12 | class Author(BaseModel): 13 | name:str 14 | age:int 15 | 16 | class Config: 17 | orm_mode = True 18 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | anyio==3.6.1 2 | click==8.1.3 3 | dnspython==2.2.1 4 | email-validator==1.2.1 5 | fastapi==0.78.0 6 | FastAPI-SQLAlchemy==0.2.1 7 | greenlet==1.1.2 8 | h11==0.13.0 9 | httptools==0.4.0 10 | idna==3.3 11 | psycopg2-binary==2.9.3 12 | pydantic==1.9.1 13 | python-dotenv==0.20.0 14 | python-multipart==0.0.5 15 | PyYAML==6.0 16 | six==1.16.0 17 | sniffio==1.2.0 18 | SQLAlchemy==1.4.39 19 | starlette==0.19.1 20 | typing-extensions==4.2.0 21 | uvicorn==0.18.1 22 | uvloop==0.16.0 23 | watchfiles==0.15.0 24 | websockets==10.3 25 | --------------------------------------------------------------------------------