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.9.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.9-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: columbus-0.1.9.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.9.tar.gz
Algorithm Hash digest
SHA256 9671d4186c5f2eb3424b969e63644ecf0325b8a6c164328e070875759eff003e
MD5 689ac5c2b1da0916561b2ccbaf412e95
BLAKE2b-256 856158c7e5c24e05f178bbf24cbd85812f245bb5fa707ce34b985e0be43c0c52

See more details on using hashes here.

File details

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

File metadata

  • Download URL: columbus-0.1.9-py3-none-any.whl
  • Upload date:
  • Size: 9.2 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.9-py3-none-any.whl
Algorithm Hash digest
SHA256 4264b1fa51b43fa8c427d4d6e32c2e62b8d5c3606333722137dc6db5fd0ec106
MD5 05fdd12d75ac01080598dbd967aea20b
BLAKE2b-256 b2de0334bb88f0c1d3de4cb62661e4377357ba00053c020a7bfca78eb198d158

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