Skip to content

Repository files navigation

The Object API

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.

Features

  • 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

Installation

pip install object-api

Usage

fromobject_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.servicemethodimportservicemethod
fromobject_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()

Documentation

https://github.com/ComputaCo/object-api

Roadmap

[] Make the Create/Read/UpdateModel's automatically convert foreign lists/dicts to just their ID's

License

MIT

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages