ObjectAPI provides a concise negative-boilerplate paradigm for creating full-stack web applications with Python. It is built on top of FastAPI, SQLModel, and pydantic.
- Active record pattern for database access
- Automatic get_by_id lookup for instance methods with route decorators
- Automatic CRUD routes
- Scheduled service methods
- Managed DB sessions for service methods and for each request
__post_init__for entity classes
pip install object-apifromobject_api.entityimportEntityfromobject_api.appimportAppfromobject_api.model_variantsimport (
create_variant,
read_variant,
update_variant,
db_variant,
)
fromobject_apiimportrouterfromobject_api.routerimportroute, get, post, put, delete, patch, head, optionsfromobject_api.servicemethodimportservicemethodfromobject_apiimport (
App,
Entity,
create_variant,
read_variant,
update_variant,
db_variant,
router,
route,
get,
post,
put,
delete,
patch,
head,
options,
servicemethod
)
@create_variant()@read_variant()@update_variant()@db_variant(include=["passwd_hash"])classUser(Entity):
name: strpasswd_hash: str=Field(exclude=True)
birthdate: datetime@propertydefage(self) ->timedelta:
returndatetime.now() -self.birthdateclassUser(Entity):
name: strpass: strage: int@service.servicemethod@classmethoddefremove_inactive(cls):
foruserinUser.get_all():
ifuser.age>100:
user.delete()
@router.route()defget_name(self):
returnself.name@router.post("/change_name")defchange_name(self, name: str):
self.name=nameself.save()
app=App()
app.run()https://github.com/ComputaCo/object-api
[] Make the Create/Read/UpdateModel's automatically convert foreign lists/dicts to just their ID's