Skip to main content

Generate an async web API from an SQLAlchemy table

Project description

Columbus

PyPI

What is Columbus?

Columbus is a Python web framework that automatically generates an async CRUD REST API web application from an SQLAlchemy table.

How does it work?

Under the hood Columbus uses Starlette, Databases and SQLAlchemy along with some interesting metaprogramming techniques to generate a web app based solely on your YAML specification and SQLalchemy table definition.

Installation

pip install columbus

Quickstart

You can have your API up and running in only a couple of simple steps:

  1. start

    This command will generate two files for you: main.yml with a basic config template and an empty models.py.

  2. In models.py define your database table using SQLAlchemy.

    Then create the tables (Alembic is generally the recommended way to do this) and add some data whichever way you like. Columbus doesn't need you to connect to the database or write any queries for the app to work, it will do that for you. All you need to do is provide it with the database url.

  3. In main.yml add the database url as a value for the 'database' key. Add the name of your table as the value for the 'table' key.

    Here is a basic working example (provided you've set up the database with this url and your table is named my_table and located in models.py).

    models: models.py
    database: postgresql://someuser:postgres@localhost/mydatabase
    APIs:
      hello_world:
        table: my_table
        methods: [GET]
    
  4. run

    This command will run your app. Navigate to localhost:8000/my_table and see your API in action.

Documentation

Here is a comprehensive list of possible keys and values in the YAML config.

Keys:

  • models: relative path to the file where your SQLAlchemy table is defined

  • database: valid database url

  • APIs: the APIs you want Columbus to generate. Each API can be named whatever you want, but it has two mandatory keys:

    • table: name of SQLAlchemy table from which you want to generate the API

    • methods: list of http methods (GET, PUT, POST, DELETE) you want the API to support. Attention: this is the only key that needs to be a list, so put the methods in square brackets.

Below is an example of a more comprehensive animals API, which should give you a feel for the correct YAML structure Columbus understands. Incorrect structures will throw an error and the app won't run.

models: models.py
database: postgresql://someuser:postgres@localhost/mydatabase
APIs:
  dogs:
    table: dogs
    methods: [GET, POST]
  cats:
    table: cats   
    methods: [GET, POST, PUT, DELETE] 
  snakes:
    table: snakes
    methods: [GET, POST, PUT]   
  bears:
    table: bears
    methods: [GET]    

What use cases does it support?

Columbus is still in the early days of active development, so it only supports the most basic use case for now. Feel free to open an issue for a missing feature and it will most likely be pushed to the top of the priority list and shipped soon.

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

columbus-0.1.tar.gz (12.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

columbus-0.1-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file columbus-0.1.tar.gz.

File metadata

  • Download URL: columbus-0.1.tar.gz
  • Upload date:
  • Size: 12.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.9.12 Darwin/21.3.0

File hashes

Hashes for columbus-0.1.tar.gz
Algorithm Hash digest
SHA256 19565a8040968fef4c392f13ace97b949d68db2843aacab2a20b6bdd19b3497e
MD5 fa6961883d982edbe8cdfc761a046006
BLAKE2b-256 de88b5609a21c5fee97c9bed44c0cd45c993fa6e90988f3ab6aecde61a878b86

See more details on using hashes here.

File details

Details for the file columbus-0.1-py3-none-any.whl.

File metadata

  • Download URL: columbus-0.1-py3-none-any.whl
  • Upload date:
  • Size: 9.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.9.12 Darwin/21.3.0

File hashes

Hashes for columbus-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b58aee93b665e6911f0960ca25b1604be6cc7013a82d8d87ad07e42a94143556
MD5 e6fcab69d019093b5bc96027e4dd3bf7
BLAKE2b-256 45e5417ae17e120c4e7760416007aa94d40c961f6636b1463ee95024eb21a166

See more details on using hashes here.

Supported by

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