Hand Me The Flask:

My Experience Building a Server in Python

Brandon Yu

https://github.com/Brandoncyu/galvanize-snacks-api-python

Intro

  • For my project, I was tasked with building a server in Python.
  • This required me to not only learn the language, but to also also learn Flask.
  • Flask is a framework written in Python with built-in commands to help you build servers.
  • I divided my time by spending:
    • 4 days learning Python
    • 3 days learning Flask
    • 2 days building the sever itself
  • How'd it turn out? Let's go see!

DEMO

For Python:

  • For one, curly brackets are not needed to set the scope of functions. Indentations are used instead.
  • Different definitions: arrays are called lists in python, objects are called dictionaries. Functions are also declared with def() rather than function().
  • All lists are actually mutable, so you have to be careful when setting one variable equal to another. If you make a change to one of the variables it affects the original one as well.
  • Python makes good use of tuples, which are like arrays but cannot be changed. Uses ().
  • Other Python objects I found interesting: Decorators (which I gathered is a way to perform callback functions), Generators (an iterator that does not store variables into memory, resulting in a quicker turnaround), and Lambdas (one-line functions for one-time use).

Differences

For Flask:

  • Has some similarities to Express. Uses models folder to interact with data.
  • Rather than building a controllers folder, Flask utilizes something called Resources.
  • These Resources are classes, with built-in method names for REST routes calls.
  • Therefore rather than writing a unique route for each individual REST route, you can now have a single route and attach a Resource that contains several REST-ful routes that you assign.
  • I also used SQL-lite to help build my database, and I did not find seeding the data very easy. Had to change some of the seed data that Justin included in order to fit it (e.g., changing them from arrays/lists to tuples, getting rid of the keys).

Differences

  1. Learn to readjust
  2. There's more than one way to skin a cat
  3. The hardest part is starting

3 Pieces of Advice

Questions?

Hand Me The Flask

By Brandon Yu

Hand Me The Flask

  • 410