A user-friendly tool to create a database-abstraction REST API.
Project description
Cobblestone
Cobblestone is a project templater to create a database-abstraction REST API. Just like Django, Cobblestone is not intended to implement a fully tailored database-modeling API; instead, it provides a generic starting architecture - then it's up to you to create your custom API by adding files!
Cobblestone is here to help you prototype and develop REST APIs super quickly. In particular, it provides you with an automatic router for all the resources you register to easily list instances, create a new instance, get an instance by unique id… It also offers a common way of defining your models no matter the database system you choose.
The full documentation is available over here.
TL;DR
Note: check out the official Getting started guide for more details on setting up a Cobblestone project.
Install the Cobblestone Python library
Note: it is recommended to use a virtual env to avoid mixing up all of your dependencies. For example, you can use venv
or pipenv
to make a clean environment for your project.
To install the Cobblestone module, run:
pip install mp.cobblestone
Initialize a new project
You now have a new CLI command available: cobblestone init
. To create your project, simply run:
cobblestone init <project_name>
Start up the project
To run your newly created project, simply use the cobblestone start
command:
cobblestone start [--debug] <project_name>
⚠️ This command will require Docker to be up and running on your computer.
Test it out!
To check everything is working:
-
go to http://localhost:8000/docs: you should see a nice Swagger doc with some auto-generated endpoints for the "user" resource! However, you need some users in your database to access them because they are protected via the OAuth2 scheme and require an access token.
-
run the database init script to create an admin user:
python db_init.py
By default, this script will only add an admin user to the database (with login "admin" and password "admin"). You may create your own users in addition by passing extra args to the script:
python db_init.py --users <user1>:<pwd1> <user2>:<pwd2> ...
-
finally, head back to the Swagger doc and try to run the
/users-me
endpoint. First, click on the lock at the top-right corner and use one of the users you created (or the admin one) to log in; then, click on "Try it out" and execute the request: this should return a JSON payload with the login, firstname, lastname and unique id of the user you connected as.
Deploy and run the project with Docker
When you are satisfied with your API, you may want to deploy the whole project. To do so easily, you can containerize it using Docker. To help you in this task, Cobblestone CLI has various Docker-like commands: deploy
, run
and stop
.
To create and run a Docker image containing your API (plus the associated database if need be), run:
cobblestone deploy <project_name>
cobblestone run <project_name>
To stop your API docker (and the associated database container if there is one), use:
cobblestone stop <project_name>
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 mp.cobblestone-1.2.3.tar.gz
.
File metadata
- Download URL: mp.cobblestone-1.2.3.tar.gz
- Upload date:
- Size: 40.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 68400d38f932b97dd61fcb1097f763014aaea7703fa2d6fe3cfca775b7f4740b |
|
MD5 | 771fb260c87d93c1142115ba99609990 |
|
BLAKE2b-256 | b5589586db122f994824ebbe403dba482c56ce89c029f44a4f50f70b55ae69a3 |
Provenance
File details
Details for the file mp.cobblestone-1.2.3-py3-none-any.whl
.
File metadata
- Download URL: mp.cobblestone-1.2.3-py3-none-any.whl
- Upload date:
- Size: 70.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc73c38fb627b3feb7bcd508cbc4bb309b8688cefd276639194ab3eaffec82b0 |
|
MD5 | 4f69e3af8c0b719cc6f9bb949211fedd |
|
BLAKE2b-256 | d444b8bd56332d402da284d9fa4bb6178413f487a01666bd10138cd3342a51d6 |