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.api import CrudAPI
from crudapi.models.base 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(
    orm_model=Book,
    response_model=Book,
    create_model=BookCreate,
    update_model=BookUpdate,
    title="Books",
)

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


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.2.0.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

crudapi-0.2.0-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: crudapi-0.2.0.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.9.7 Linux/5.8.0-1041-azure

File hashes

Hashes for crudapi-0.2.0.tar.gz
Algorithm Hash digest
SHA256 ec5c52482eba193a7cb1ad1b7d0ad510492b4b266ce0c9bb7ca63b7b581d21f7
MD5 5899be525171ddb0ee6ccdfb44a58db0
BLAKE2b-256 68f8422f42334b53bc47ab9d7d3d7cb19e9176dcbe9c51b25566778c09889195

See more details on using hashes here.

File details

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

File metadata

  • Download URL: crudapi-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 11.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.9.7 Linux/5.8.0-1041-azure

File hashes

Hashes for crudapi-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 54e210fbaff7462d2b9a09367cac7c77347e32c1b5e2ebb06e3c558f833317f1
MD5 c5f4775a8dc135013ac4915bb7bc7d73
BLAKE2b-256 996c296d232524d31043d63f97874c9136b94b66014ea5e58e6d43f4f45aac82

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