Skip to content

A quick template for using Flask, MongoDB, PostreSQL, D3

Notifications You must be signed in to change notification settings

benjamenalford/generic_flask

Repository files navigation

Generic Flask Api and D3 Template

A couple simple examples of Flask to use as project starters on their own or stitched together. I've been using these

The main idea was to create a few working examples of common app starters with enough starter code to get going while also keeping everything as simple as possible. Let's not be clever,let's be clear. When an idea strikes here's just enough to connect the dots between UI and server.

Coments are only included to explain points that may need attention, explain the thought behind the logic and code, and may exceptions from the normal flow.

Examples

HTML Templates

  • Home page - page rendered using flask to create the elements on the page before it's sent to the browser. see Jinja templates for documentation and more examples(no api used)
  • Default Page - basic example in the consoles
  • Post Example - entering data in the browser and sending it back to Flask for processing and returning the result and displaying on the page and in the consoles
  • Knn Prediction Example - entering data in the browser and sending it back to Flask for predicting against a knn model and returning the result and displaying on the page and in the consoles

General

Libraries Used

Another design consideration with this project was to include as little dependcies as possiple while still providing enough to create begin creating a POC or utility with enough to make something that looks and functions well.

Little enough is included so that adding anything else one might need won't be an issue. Everything here is easily replaced and meant to be.

There's no configuration to mess with other than your own URLS ( which have been defaulted to OOTB and local instances of any servers) , any config is done where it's needed, when it's needed. Let's not spend 1 hour configuring a larger framework or get stuck on some benign minute of new lib X; let's get to work.

Libraries were chosen for their OOTB usuability, quality of official documentation, user community, extendability, adability, and general usage in the 'industry', coprorate world, and real world. With just the included examples, official site examples and documentation, code complete , your can just start writing code.

  • JS - Older versions are used and this is intentional, life is not always cutting edge. Upgrade away and you shouldn't have any issues.
    • D3.js v5 - Swiss army knife of data manipulation and visualizations
    • Bootstrap v5 - the js is here to support the css, but you can get fancy with it if you need to.
  • Python
    • Flask - It is what it is, a decent little web server in python
    • numpy - because
    • sqlalchemy - adapts to most databases, go commando or ORM depending on the mood.
    • pymongo - gets the job done
    • sklean - the ML toolbox
  • UI
    • Bootstrap - It's default looks better than browser default,
  • Databases
    • Postgres - It's used everywhere
    • MongoDb - the 'it could be anything' of no-sql databases, free cloud hosting as well.
Open License - I don't care what you do with this. if someone actually uses it or finds it helpful, let me know (or not)