background preloader

Designing a RESTful API with Python and Flask

Designing a RESTful API with Python and Flask
In recent years REST (REpresentational State Transfer) has emerged as the standard architectural design for web services and web APIs. In this article I'm going to show you how easy it is to create a RESTful web service using Python and the Flask microframework. What is REST? The characteristics of a REST system are defined by six design rules: Client-Server: There should be a separation between the server that offers a service, and the client that consumes it.Stateless: Each request from a client must contain all the information required by the server to carry out the request. What is a RESTful web service? The REST architecture was originally designed to fit the HTTP protocol that the world wide web uses. Central to the concept of RESTful web services is the notion of resources. The HTTP request methods are typically designed to affect a given resource in standard ways: The REST design does not require a specific format for the data provided with the requests. Designing a simple web service Related:  python

The Flask Mega-Tutorial, Part I: Hello, World! This is the first article in a series where I will be documenting my experience writing web applications in Python using the Flask microframework. NOTE: This article was revised in September 2014 to be in sync with current versions of Python and Flask. Here is an index of all the articles in the series that have been published to date: My background I'm a software engineer with double digit years of experience developing complex applications in several languages. In addition to Python, I've written web apps in PHP, Ruby, Smalltalk and believe it or not, also in C++. UPDATE: I have written a book titled "Flask Web Development", published in 2014 by O'Reilly Media. The application The application I'm going to develop as part of this tutorial is a decently featured microblogging server that I decided to call microblog. These are some of the topics I will cover as we make progress with this project: So as you see, I'm going pretty much for the whole thing. Requirements Installing Flask #! . Miguel

SQLAlchemy - The Database Toolkit for Python python-reference/ at master · justmarkham/python-reference REST web services with Python, MongoDB, and Spatial Data Let’s get you going quickly with Python, MongoDB, and Spatial data on OpenShift As a follow up to my last post about getting spatial going in MongoDB on OpenShift, today we are going to put a web service in front of it using Python. There are several goals for this article: Learn a little bit about Flask – a Python web frameworkLearn about how to connect to MongoDB from PythonCreate a REST Style web service to use in our SoLoMo application I hope by the end you can see how using a Platform as a Service can get you going with Python, MongoDB, and Spatial faster than you can say…“Awesome Sauce”. Creating the Python application Here is OpenShift the command line to create the Python app rhc app create -t python-2.6 -a pythonws Using the flask quickstart from GitHub We have already put together a flask quickstart in the openshift github space. cd pythonws git remote add upstream -m master git pull -s recursive -X theirs upstream master

Install Python 2.7, virtualenv and virtualenvwrapper on OS X This post explains how to install a clean version of Python in a Mac OS X Mavericks/Yosemite. You’ll also learn to install and use the virtualenv and virtualenvwrapper tools to create virtual environments for your projects. Install Xcode and Homebrew First of all, install Xcode if you don’t have it already. Next, we need to install the Command Line Tools of Xcode. this should trigger a pop-up window that will ask you to install the Command Line Tools. Next, we need to install Homebrew. $ ruby -e "$(curl -fsSL Note: The previous line updates often, so you may want to check the official site for the updated command line –> Homebrew. Now, we need to insert the Homebrew directory at the top of the PATH environment variable. export PATH=/usr/local/bin:$PATH Note: Usually, in Linux, Unix and Mac systems, the file .bash_profile is executed to configure your shell when you log in via console. Install Python 2.7 or Wooha!

Django, le framework Web-Python — Django Story 1.0 documentation Qu’est-ce que Django ?¶ Django est un framework développé en Python, initialement pour un journal local dans le Kansas : World Online. Un peu d’histoire¶ En 2003, deux développeurs (Adrian Holovaty et Simon Willison) ont décidé d’abandonner le langage PHP pour se mettre au Python afin de développer leur site dédié aux faits actuels. C’est en 2005 que World Online décide d’ouvrir les portes de son framework : Django. Pourquoi “Django” ? Le nom « Django » a été donné en souvenir de Django Reinhardt, guitariste jazz ayant vécu de 1910 à 1953. Pour plus d’informations sur Django et ses origines, je vous redirige sur la FAQ officielle du projet [en]. Pourquoi utiliser Django ? Pourquoi utiliser un Framework ? Lorsque l’on réalise un site Internet, on en revient toujours aux même étapes : Tout cela est relativement répétitif, et si, la première fois, ça peut paraître très amusant, on en arrive rapidement à faire des copier/coller, assez mauvaise méthode car source de nombreuses erreurs. #!

My virtualenv and virtualenv wrapper cheat sheet. I alias the commands of virtualenv and virtualenv wrapper for my own development environment. Ben's VirtualEnv Cheatsheet This cheat sheet describes my usage/implementation of virtualenv with virtualenv wrapper and the bash foo that I added with the help of many blogs to make it all tick together in fun land. Quick Reference $ echo $WORKON_HOME /Users/benjamin/.virtualenvs $ echo $PROJECT_HOME /Users/benjamin/Repos/git/ Commands All of the commands below are to be used on the Terminal Command line. venv List or change working virutal environments (alias workon) venv [environment_name] venv.exit Switch from the virtual environment back to system Python (alias deactivate) venv.exit List all of the environments (alias lsvirtualenv) [-b] [-l] [-h] -b Brief mode, disables verbose output -l Long mode, verbose output, default -h Print help Show the details for a single virtualenv [env] venv.init Create a new environment in the WORKON_HOME (alias mkvirtualenv) venv.init ENVNAME venv.init [-a project_path] [-i package] [-r requirements.txt] [virtualenv opts] ENVNAME

Welcome to District Data Labs - How to Develop Quality Python Code How to Develop Quality Python Code Workflows and Development Tools Benjamin Bengfort Developing in Python is very different from developing in other languages. Python is an interpreted language like Ruby or Perl, so developers are able to use read-evaluate-print loops (REPLs) to execute Python in real-time. Python sits in the middle of these paradigms, providing the best of many worlds. However, the breadth of Python means that there is no one workflow to developing with it, and certainly there is no standard IDE or environment framework to make these decisions on your behalf. A Development Environment So what do you need in order to successfully develop data apps with Python? A text editor - Sublime, Notepad++, Vim, Emacs, and Text Wrangler all work.A terminal with the python executable in your path. That's it! IDLE - this environment will be familiar to Windows users who probably executed their first Python commands in it. Third Party Libraries $ pip install requests Virtual Environments

Django REST framework Overview The Notebook is the place for all your needs Data Ingestion Data Discovery Data Analytics Data Visualization & Collaboration Multiple language backend Zeppelin interpreter concept allows any language/data-processing-backend to be plugged into Zeppelin. Adding new language-backend is really simple. Apache Spark integration Zeppelin provides built-in Apache Spark integration. Zeppelin's Spark integration provides Automatic SparkContext and SQLContext injectionRuntime jar dependency loading from local filesystem or maven repository. Data visualization Some basic charts are already included in Zeppelin. Pivot chart With simple drag and drop Zeppelin aggeregates the values and display them in pivot chart. Learn more about Zeppelin's Display system. ( text, html, table, angular ) Dynamic forms Zeppelin can dynamically create some input forms into your notebook. Learn more about Dynamic Forms. Collaboration Notebook URL can be shared among collaborators. Publish 100% Opensource Undergoing Incubation