Skip to main content

The easiest way to create your Restful CRUD APIs

Project description

CrudAPI: The easiest way to create your CRUD APIs

codecov Code style: black PyPI version

Combining the power of FastAPI and SQLModel, you'll only have to care about modeling your data and we'll take care of building up a RESTful API for it.

from typing import Optional

from sqlmodel import Field
from sqlmodel import SQLModel

from crudapi import CrudAPI
from crudapi.models import BaseModel


class BookUpdate(SQLModel, table=False):

    description: Optional[str] = Field(nullable=True)
    review: Optional[str] = Field(nullable=True)


class BookCreate(BookUpdate):

    title: str = Field(nullable=False)


class Book(BookCreate, BaseModel, table=True):

    __tablename__ = "books"


crud =  CrudAPI()
crud.include_model(
    orm_model=Book,
    create_model=BookCreate,
    update_model=BookUpdate,
)

you'll get, out of the box, a working crudapi with all these working REST endpoints:

  • GET: /books
  • POST: /books
  • GET: /books/<id>
  • PATCH: /books/<id>
  • PUT: /books/<id>
  • DELETE: /books/<id>

and because CrudAPI subclasses FastAPI you'll also get all the incredible features of this wonderful library, including automatic OpenAPI schema generation and a working SwaggerUI:

SwaggerUI generated from demo code


Samples

Under the /samples directory you'll find some CrudAPIs to help you understand the included features of this library.

Pay special attention to the definitions on samples/models.py and how they relate to the automagically generated OpenAPI specification and APIs.

We've also commited the .vscode/launch.json configuration file. With it, if you are a VSCode user you'll be able to launch some test & debugging servers.


Development

We use Poetry for packaging and dependency management:

poetry install

poetry shell

We use Pytest for testing:

pytest

You can start a testing server running:

uvicorn tests.server:app --reload

Acknowledgments

This wouldn't be possible without the great people working in the following open source projects. Eternal thanks to all of them.

  • SQLAlchemy "The database toolkit for python."
  • Starlette "The little ASGI framework that shines."
  • pydantic "Data validation and settings management using Python type hinting."
  • FastAPI "FastAPI framework, high performance, easy to learn, fast to code, ready for production."
  • SQLModel "SQLModel, SQL databases in Python, designed for simplicity, compatibility, and robustness."

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

crudapi-0.5.0.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

crudapi-0.5.0-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

Details for the file crudapi-0.5.0.tar.gz.

File metadata

  • Download URL: crudapi-0.5.0.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.10 CPython/3.9.7 Linux/5.11.0-40-generic

File hashes

Hashes for crudapi-0.5.0.tar.gz
Algorithm Hash digest
SHA256 1b4bb50f146b1224355fabf334e9ff2441b1875dce78bed782a226dba62e58f0
MD5 ab7a071295c6b2108015f993b1f19e69
BLAKE2b-256 14b928090867bda8b3789addcc21d95cacaaaa3bc6738679a826cf7c1c96104e

See more details on using hashes here.

File details

Details for the file crudapi-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: crudapi-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 14.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.10 CPython/3.9.7 Linux/5.11.0-40-generic

File hashes

Hashes for crudapi-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 65857f8f5f04b317f84043242a1577b2c3d645173504ca3cca8f33214f40c557
MD5 19ff3668be717056b1f688fc2a818cd4
BLAKE2b-256 f9ac2941d55d06b30782ccdaf323a196ebb2df0e8d3e99fc14c3a3ca51dc1921

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page