package for automatically creating an api on an existing database
Project description
Apifactory
Apifacotry allows you to create APIs on existing (currently only SQL) databases nearly automatically. It handles all sorts of setup automatically for you, including creating pydantic data schemas setting up login and JWT.
Apifactory uses SQLAlchemy to automatically detect tables in the given database. If these tables have single column primary keys they are added to your API, multicolumn primary keys will be added in the future.
Apifactory uses fastapi to construct its APIs. This means the schemas you accept or return in your API are defined by pydantic, which also handles validation of input types and return types. These schemas are automatically generated from the SQLAlchemy table models that are generated by apifactory.
Apifactory automatically prevents unauthorized access. Users of your API need to log in and get a JWT to authenticate at the API endpoints Authorization is based on a user defined existing Users table.
A short example how to set up an API
Apifactory will add all tables with a single column primary key. All columns of these table will be added to the schema of your API. However, this might not be preferred for all methods. For example, you might not want your post requests to also dictate the primary key the entry. This could for example be handled by the database itself. Currently, you can add some config to dictate which columns to exclude in post and put requests. In addition, you need to specify the database connection string. And specify the name of the table containing hashed passwords for user authentication.
from apifactory.app_factory import ApiFactory
dburl = "<database url>"
key = "<key for jwt encryption>"
configs = {
"Persons": {
"excluded_columns_put": ["Personid", "createdDate"],
"excluded_columns_post": ["Personid", "createdDate"],
},
"test_table": {"excluded_columns_put": ["primarykey"]},
}
usermodel_name = 'Users'
app = ApiFactory(dburl, usermodel_name, key, configs).app_factory()
You can serve the file
uvicorn <name of your file containg the app>:app
Since apifactory uses fastapi you automatically can visit an openapi page containing the details of your API.
Documentation is available here.
Apifactory is currently heavily under development and not feature complete/stable. Features to be included in the future:
- More configuration options
- Multicolumn primary key support
- Add scopes to JWT
- Make apifactory completely asynchronous
- Add support for custom models
- Custom endpoint
- logging
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file apifactory-0.6.0.tar.gz
.
File metadata
- Download URL: apifactory-0.6.0.tar.gz
- Upload date:
- Size: 15.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.4 CPython/3.9.4 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6b472cca156ef47bd547ccd5e78d3838d4e16952ba45dee2583afeac83f4f886 |
|
MD5 | 2b3ff6b5c26b4cabd2224217994ddb97 |
|
BLAKE2b-256 | 50be89e9666ada775d463d2ca67028bc993bd9b51fbe26884ca9b42a059c7892 |
File details
Details for the file apifactory-0.6.0-py3-none-any.whl
.
File metadata
- Download URL: apifactory-0.6.0-py3-none-any.whl
- Upload date:
- Size: 17.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.4 CPython/3.9.4 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3f1849ba9b2cc1239f16c856f1c763d77739dab9dd672b82f68cdc1f0285a078 |
|
MD5 | 40ad1d138f14d2a50694d3b5c2144b94 |
|
BLAKE2b-256 | 628cb654b98eb1fab39310163de6f80e6682ded202ed595ef729b3d57206350a |