Skip to main content

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:

  1. 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.

  2. 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> ...
    
  3. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mp.cobblestone-1.3.0.tar.gz (43.2 kB view details)

Uploaded Source

Built Distribution

mp.cobblestone-1.3.0-py3-none-any.whl (80.8 kB view details)

Uploaded Python 3

File details

Details for the file mp.cobblestone-1.3.0.tar.gz.

File metadata

  • Download URL: mp.cobblestone-1.3.0.tar.gz
  • Upload date:
  • Size: 43.2 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

Hashes for mp.cobblestone-1.3.0.tar.gz
Algorithm Hash digest
SHA256 d67b352d5e3665ff759e1f3336038413ba9926cb4475fc11dcdbc93db56884c1
MD5 fe0a508f4452e7c9d94b8096a0faea0a
BLAKE2b-256 9d648bcc6c3025da3cc0e4f9a60286d224cfa4d90bea963c048e7c9478e9d529

See more details on using hashes here.

Provenance

File details

Details for the file mp.cobblestone-1.3.0-py3-none-any.whl.

File metadata

  • Download URL: mp.cobblestone-1.3.0-py3-none-any.whl
  • Upload date:
  • Size: 80.8 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

Hashes for mp.cobblestone-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 feccaa998f3f9ca3fce1c03515af617dbf8189cc9cfed9bf34fd79768168a3aa
MD5 b517c90202977dd128b77136c32f467f
BLAKE2b-256 60fa6c58ee0b2cd2c1d233303a2218ca3435a359e093bf8a76724b8a3c48564f

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page