kandi background

fastapi | FastAPI framework, high performance | REST library

Download this library from

kandi X-RAY | fastapi Summary

fastapi is a Python library typically used in Web Services, REST, Fastapi, Swagger applications. fastapi has no bugs, it has no vulnerabilities, it has a Permissive License and it has high support. However fastapi build file is not available. You can install using 'pip install fastapi' or download it from GitHub, PyPI.
FastAPI is a modern, fast (high-performance), web framework for building APIs with Python 3.6+ based on standard Python type hints.

kandi-support Support

  • fastapi has a highly active ecosystem.
  • It has 44054 star(s) with 3388 fork(s). There are 587 watchers for this library.
  • There were 9 major release(s) in the last 6 months.
  • There are 996 open issues and 1816 have been closed. On average issues are closed in 35 days. There are 478 open pull requests and 0 closed requests.
  • It has a positive sentiment in the developer community.
  • The latest version of fastapi is 0.75.2

quality kandi Quality

  • fastapi has 0 bugs and 0 code smells.

securitySecurity

  • fastapi has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
  • fastapi code analysis shows 0 unresolved vulnerabilities.
  • There are 0 security hotspots that need review.

license License

  • fastapi is licensed under the MIT License. This license is Permissive.
  • Permissive licenses have the least restrictions, and you can use them in most projects.

buildReuse

  • fastapi releases are available to install and integrate.
  • Deployable package is available in PyPI.
  • fastapi has no build file. You will be need to create the build yourself to build the component from source.
  • Installation instructions, examples and code snippets are available.
  • fastapi saves you 16583 person hours of effort in developing the same functionality from scratch.
  • It has 48740 lines of code, 2321 functions and 790 files.
  • It has low code complexity. Code complexity directly impacts maintainability of the code.
Top functions reviewed by kandi - BETA

kandi has reviewed fastapi and discovered the below as its top functions. This is intended to give you an instant insight into fastapi implemented functionality, and help decide if they suit your requirements.

  • Generate OpenAPI path .
  • Solve dependencies .
  • Encoder for JSONable encodings .
  • Include the given router .
  • Returns a request handler .
  • Build documentation for lang .
  • Convert request body to args .
  • Return html for swagger UI .
  • Get the swagger UI .
  • Create OpenAPI format .

fastapi Key Features

Fast: Very high performance, on par with NodeJS and Go (thanks to Starlette and Pydantic). One of the fastest Python frameworks available.

Fast to code: Increase the speed to develop features by about 200% to 300%. *

Fewer bugs: Reduce about 40% of human (developer) induced errors. *

Intuitive: Great editor support. Completion everywhere. Less time debugging.

Easy: Designed to be easy to use and learn. Less time reading docs.

Short: Minimize code duplication. Multiple features from each parameter declaration. Fewer bugs.

Robust: Get production-ready code. With automatic interactive documentation.

Standards-based: Based on (and fully compatible with) the open standards for APIs: OpenAPI (previously known as Swagger) and JSON Schema.

fastapi Examples and Code Snippets

  • Installation
  • Create it
  • Run it
  • Check it
  • Example upgrade
  • Recap
  • FastAPI - GET request results in typeerror (value is not a valid dict)
  • Conditional call of a FastApi Model
  • fastapi (starlette) RedirectResponse redirect to post instead get method
  • uvicorn [fastapi] python run both HTTP and HTTPS
  • how to render a json from a dataframe in fastAPI
  • FastAPI - Pydantic - Value Error Raises Internal Server Error
  • Kill a python subprocess that does not return
  • "422 Unprocessable Entity" error when making POST request with both attributes and key using FastAPI
  • How to apply transaction logic in FastAPI RealWorld example app?
  • Custom OpenMetrics Not Being Propagated to DataDog

Installation

$ pip install fastapi

---> 100%

Community Discussions

Trending Discussions on fastapi
  • FastAPI - GET request results in typeerror (value is not a valid dict)
  • Conditional call of a FastApi Model
  • fastapi (starlette) RedirectResponse redirect to post instead get method
  • uvicorn [fastapi] python run both HTTP and HTTPS
  • how to render a json from a dataframe in fastAPI
  • FastAPI - Pydantic - Value Error Raises Internal Server Error
  • Kill a python subprocess that does not return
  • "422 Unprocessable Entity" error when making POST request with both attributes and key using FastAPI
  • FastAPI responding slowly when calling through other Python app, but fast in cURL
  • How to apply transaction logic in FastAPI RealWorld example app?
Trending Discussions on fastapi

QUESTION

FastAPI - GET request results in typeerror (value is not a valid dict)

Asked 2022-Mar-23 at 22:19

this is my database schema.

enter image description here

I defined my Schema like this:

from pydantic import BaseModel

class Userattribute(BaseModel):
    name: str
    value: str
    user_id: str
    id: str

This is my model:

class Userattribute(Base):
    __tablename__ = "user_attribute"

    name = Column(String)
    value = Column(String)
    user_id = Column(String)
    id = Column(String, primary_key=True, index=True)

In a crud.py I define a get_attributes method.

def get_attributes(db: Session, skip: int = 0, limit: int = 100):
    return db.query(models.Userattribute).offset(skip).limit(limit).all()

This is my GET endpoint:

@app.get("/attributes/", response_model=List[schemas.Userattribute])
def read_attributes(skip: int = 0, limit: int = 100, db: Session = Depends(get_db)):
    users = crud.get_attributes(db, skip=skip, limit=limit)
    print(users)
    return users

The connection to the database seems to work, but a problem is the datatype:

pydantic.error_wrappers.ValidationError: 7 validation errors for Userattribute
response -> 0
  value is not a valid dict (type=type_error.dict)
response -> 1
  value is not a valid dict (type=type_error.dict)
response -> 2
  value is not a valid dict (type=type_error.dict)
response -> 3
  value is not a valid dict (type=type_error.dict)
response -> 4
  value is not a valid dict (type=type_error.dict)
response -> 5
  value is not a valid dict (type=type_error.dict)
response -> 6
  value is not a valid dict (type=type_error.dict)

Why does FASTApi expect a dictionary here? I don´t really understand it, since I am not able to even print the response. How can I fix this?

ANSWER

Answered 2022-Mar-23 at 22:19

SQLAlchemy does not return a dictionary, which is what pydantic expects by default. You can configure your model to also support loading from standard orm parameters (i.e. attributes on the object instead of dictionary lookups):

class Userattribute(BaseModel):
    name: str
    value: str
    user_id: str
    id: str

    class Config:
        orm_mode = True

You can also attach a debugger right before the call to return to see what's being returned.

Since this answer has become slightly popular, I'd like to also mention that you can make orm_mode = True the default for your schema classes by having a common parent class that inherits from BaseModel:

class OurBaseModel(BaseModel):
    class Config:
        orm_mode = True


class Userattribute(OurBaseModel):
    name: str
    value: str
    user_id: str
    id: str

This is useful if you want to support orm_mode for most of your classes (and for those where you don't, inherit from the regular BaseModel).

Source https://stackoverflow.com/questions/69504352

Community Discussions, Code Snippets contain sources that include Stack Exchange Network

Vulnerabilities

No vulnerabilities reported

Install fastapi

You will also need an ASGI server, for production such as Uvicorn or Hypercorn.
Now modify the file main.py to receive a body from a PUT request. Declare the body using standard Python types, thanks to Pydantic. The server should reload automatically (because you added --reload to the uvicorn command above).

Support

For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .

Build your Application

Share this kandi XRay Report