Giter VIP home page Giter VIP logo

insights_connexion's Introduction

Insights Connexion

This is a python package intended to be used as a base for an Insights Platform REST API application. It does all the boilerplate required to use a Postgres database with Connexion/Flask API.

Installation

pipenv install -e "git+git://github.com/RedHatInsights/insights_connexion.git#egg=insights_connexion" -d

Required Project Structure

  • api/
  • app.py
  • config.ini
  • db/
    • models.py
  • swagger/
    • api.spec.yaml
  • test/
    • test.py
    • values.json

app.py

import insights_connexion.app as app
app.start()

swagger/api.spec.yaml

This is the Swagger spec for the REST API. It will be used by Connexion to automatically serve and validate the routes.

test/test.py

This is where you will define your tests. The following is an example of how to use this package's OATTS test runner

import insights_connexion.test.oatts as oatts
oatts.test()

test/values.json

This is passed to oatts --customValuesFile. See oatts for details.

db/models.py

This is where the SQLAlchemy models are defined. They can be defined anywhere, this location is just an example. The important piece is to use the base class from this package. Here's an example how to define them:

from insights_connexion.db.base import Base
from sqlalchemy import Column, String


class Tag(Base):
    __tablename__ = 'tags'

    id = Column(String, primary_key=True)

api/

This is the directory Connexion will look in for the endpoint handling functions. Each endpoint needs a separate file. See the Connexion routing docs for details. You can access the SQL Alchemy session thru this package, e.g.

from insights_connexion.db.base import session
from db.models import Tag

def search():
    tags = session.query(Tag).all()
    tags_dump = [tag.dump() for tag in tags]
    return {'count': 0, 'results': tags_dump}

config.ini

This contains all the application's configuration parameters. Each environment gets a separate section, e.g. dev, qa, prod. It requires at least the following parameters in the [DEFAULT] section (substituting the values for your app):

[DEFAULT]
db_name = tagservice
db_user = tagservice
db_password = tagservice
db_host = localhost
db_port = 5746
log_level = INFO
debug = True
port = 8080
db_pool_size = 30
db_max_overflow = 100

Migrations

Migrations should be managed by alembic. Follow the alembic doc to initialize the directory structure and create the database migration scripts.

Running The App

pipenv run python app.py

insights_connexion's People

Contributors

ckyrouac avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.