SimpleRestApi
SimpleRestAPI is the library for launch REST API based on your SQLAlchemy models.
Documentation: https://simplerestapi.readthedocs.io/en/latest/
Features
- Minimum code. You don't need create any endpoints. All of you need is your SQLAlchemy models.
- You can customize your endpoints. For example, you can deny some methods or customize the endpoint's path.
- Under hood SimpleApi use Starlette.
Installation
pip install simplerestapi
Also you need install uvicorn.
pip install uvicorn
Usage
- Create
models.py
from sqlalchemy import Column, Integer, String, create_engine
from sqlalchemy.ext.declarative import declarative_base
from simplerestapi.endpoint import ConstructEndpoint, Endpoint
Base = declarative_base(metaclass=ConstructEndpoint)
class CustomUser(Base, Endpoint):
id = Column(Integer, primary_key=True)
name = Column(String)
surname = Column(String)
age = Column(Integer)
class Car(Base, Endpoint):
id = Column(Integer, primary_key=True)
name_model = Column(String)
production = Column(String)
year = Column(Integer)
You need to add metaclass=ConstructEndpoint to parameters declarative_base and to inherit your table class from Endpoint.
You don't need to add attribute __tablename__ to your table class, because the name of the table is constructed automatic like cls.__name__.lower().
You can add class ConfigEndpoint to config your endpoint, for more information see Configuration endpoint .
- Create
app.py
import os
import uvicorn
import models
from simplerestapi.main import SimpleApi
app = SimpleApi(models, db='postgresql://db_user:db_pass@127.0.0.1/db_name')
You can use the parameter debug=False to turn off debug mode.
- Run application
uvicorn app:app.app --reload
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO: Started reloader process [250901] using statreload
INFO: Started server process [250903]
INFO: Waiting for application startup.
INFO: Application startup complete.
- Use REST API
You can use methods GET, POST, PUT, PATCH, DELETE in endpoints:
- http://127.0.0.1:8000/car - GET for retrieve list of
models.Caritems, support filters, example?name=SomeName, POST for create new item in DB. - http://127.0.0.1:8000/car/1 - GET for retrieve one item with id=1, also you can use PUT, PATCH for update item, DELETE for delete item from DB.
Similar endpoints are availible for all you models.
Metadata
Release files for simplerestapi 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| simplerestapi-1.0.2.tar.gz | 9.0 kB | Without provenance | Details for simplerestapi-1.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| simplerestapi-1.0.2-py3-none-any.whl | Python 3 | none | any | Details for simplerestapi-1.0.2-py3-none-any.whl |
Total release size: 18.0 kB
Release files / simplerestapi-1.0.2.tar.gz
| Download URL | simplerestapi-1.0.2.tar.gz |
|---|---|
| Size | 9.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9ff763973205f42500a3fb9f773b158a3ce3e623c30865abc64a9b4a745ca765
|
|
BLAKE2b-256 checksum How to use checksums |
35aa53ddd8e7d27be2534a012f2b54c708aaf320f57e4d9c64ad5542f1fb2f42
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.10
|
Release files / simplerestapi-1.0.2-py3-none-any.whl
| Download URL | simplerestapi-1.0.2-py3-none-any.whl |
|---|---|
| Size | 9.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
405446c96f953749a5fff947422511ccaa474169ae198fdd0251738d8ecb35b4
|
|
BLAKE2b-256 checksum How to use checksums |
3c4ba1472025b1cd422e70699fc56797dd80a103b000b95b6aad1fd682d9ff82
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.10
|
Security for simplerestapi 1.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.