RESTful API for searching Amazon sites
Clone or download
reubano Merge branch 'fixes'
* features:
  Bump to version 1.5.1
  Fix heroku api key
Latest commit 2b767e2 Jun 11, 2017

README.rst

AMZN Search API travis

Introduction

AMZN Search API is a Flask (About Flask) powered RESTful API wrapper to the Amazon search portal.

Requirements

AMZN Search API has been tested and known to work on the following configurations:

  • MacOS X 10.9.5
  • Ubuntu 14.04 LTS
  • Python 2.7, 3.5, and 3.6

Framework

Flask Extensions

Production Server

Quick Start

Preparation

Check that the correct version of Python is installed

python -V

Activate your virtualenv

Installation

Clone the repo

git clone git@github.com:reubano/amzn-search-api.git

Install requirements

cd amzn-search-api
pip install -r base-requirements.txt

Run API server

manage serve

Now view the API documentation at http://localhost:5000

Scripts

AMZN Search API comes with a built in script manager manage.py. Use it to start the server, run tests, and initialize the database.

Usage

manage <command> [command-options] [manager-options]

Examples

Start server

manage serve

Run tests

manage test

Run linters

manage lint

Manager options

-m MODE, --cfgmode=MODE
 set the configuration mode, must be one of ['Production', 'Development', 'Test'] defaults to 'Development'. See config.py for details
-f FILE, --cfgfile=FILE
 set the configuration file (absolute path)

Commands

runserver Runs the flask development server serve Runs the flask development server check Check staged changes for lint errors lint Check style with linters test Run nose, tox, and script tests add_keys Deploy staging app deploy Deploy staging app install Install requirements shell Runs a Python shell inside Flask application context.

Command options

Type manage <command> --help to view any command's options

manage manage serve --help

Output

usage: manage serve [-?] [-t] [-T TIMEOUT] [-l] [-o] [-p PORT] [-h HOST]

Runs the flask development server

optional arguments:

-?, --help show this help message and exit -t, --threaded Run multiple threads -T TIMEOUT, --timeout TIMEOUT

Fetch timeout
-l, --live Use live data
-o, --offline Offline mode
-p PORT, --port PORT
 The server port
-h HOST, --host HOST
 The server host

Example

Start production server on port 1000

manage serve -p 1000 -m Production

Configuration

Config Variables

The following configurations settings are available in config.py:

variable description default value
__DOMAIN__ your custom domain nerevu.com
CACHE_TIMEOUT amount of time (in seconds) to cache responses 60 minutes
API_RESULTS_PER_PAGE the number of results returned per page 24
API_MAX_RESULTS_PER_PAGE the maximum number of results returned per page 1024
API_URL_PREFIX string to prefix each resource in the api url '/api/v1'

Environment Variables

AMZN Search API references the following environment variables:

variable description
AWS_ACCESS_KEY_ID your AWS access key ID
AWS_SECRET_ACCESS_KEY your AWS access key secret
AWS_ASSOCIATE_TAG_US your AWS Associate tag for US region
AWS_ASSOCIATE_TAG_UK your AWS Associate tag for UK region

To set an environment variable, e.g. MY_ENV, do the following:

echo 'export MY_ENV=value' >> ~/.profile

Documentation

For a list of available resources, example requests and responses, and code samples, view the online documentation.

Advanced Installation

Production Server

Preparation

Getting gevent up and running is a bit tricky so follow these instructions carefully.

To use gevent, you first need to install libevent.

Linux

apt-get install libevent-dev

Mac OS X via homebrew

brew install libevent

Mac OS X via macports

sudo port install libevent

Mac OS X via DMG

download on Rudix

Installation

Now that libevent is handy, install the remaining requirements

pip install -r requirements.txt

Or via the following if you installed libevent from macports

sudo CFLAGS="-I /opt/local/include -L /opt/local/lib" pip install gevent
pip install -r requirements.txt

Foreman

Finally, install foreman

sudo gem install foreman

Now, you can run the application locally

foreman start

You can also specify what port you'd prefer to use

foreman start -p 5555

Deployment

If you haven't signed up for Heroku, go ahead and do that. You should then be able to add your SSH key to Heroku, and also heroku login from the commandline.

Install heroku and create your app

sudo gem install heroku
heroku create -s cedar app_name

Add memcachier

heroku addons:add memcachier

Push to Heroku

git push heroku master

Start the web instance and make sure the application is up and running

heroku ps:scale web=1
heroku ps

Now, we can view the application in our web browser

heroku open

And anytime you want to redeploy, it's as simple as git push heroku master. Once you are done coding, deactivate your virtualenv with deactivate.

Directory Structure

$ tree . | sed 's/+----/├──/; /.pyc/d; /.DS_Store/d'
.
├── LICENSE
├── MANIFEST.in
├── Procfile
├── README.rst
├── app
│   ├── __init__.py
│   ├── api.py
│   ├── doc_parser.py
│   ├── frs.py
│   ├── helper.py
│   ├── static
│   │   ├── favicon-16x16.png
│   │   ├── favicon-32x32.png
│   │   ├── index.html
│   │   ├── oauth2-redirect.html
│   │   ├── swagger-ui-bundle.js
│   │   ├── swagger-ui-bundle.js.map
│   │   ├── swagger-ui-standalone-preset.js
│   │   ├── swagger-ui-standalone-preset.js.map
│   │   ├── swagger-ui.css
│   │   ├── swagger-ui.css.map
│   │   ├── swagger-ui.js
│   │   └── swagger-ui.js.map
│   ├── templates
│   │   └── index.html
│   ├── tests
│   │   ├── standard.rc
│   │   ├── test.sh
│   │   ├── test_site.py
│   ├── utils.py
│   ├── views.py
├── base-requirements.txt
├── config.py
├── dev-requirements.txt
├── helpers
│   ├── check-stage
│   ├── clean
│   ├── pippy
│   ├── srcdist
│   └── wheel
├── manage.py
├── py2-requirements.txt
├── requirements.txt
├── runtime.txt
├── setup.cfg
├── setup.py
├── test.txt
└── tox.ini

Contributing

First time

  1. Fork
  2. Clone
  3. Code (if you are having problems committing because of git pre-commit hook errors, just run manage check to see what the issues are.)
  4. Use tabs not spaces
  5. Add upstream git remote add upstream https://github.com/reubano/amzn-search-api.git
  6. Rebase git rebase upstream/master
  7. Test manage test
  8. Push git push origin master
  9. Submit a pull request

Continuing

  1. Code (if you are having problems committing because of git pre-commit hook errors, just run manage check to see what the issues are.)
  2. Use tabs not spaces
  3. Update upstream git fetch upstream
  4. Rebase git rebase upstream/master
  5. Test manage test
  6. Push git push origin master
  7. Submit a pull request

Contributors

$ git shortlog -sn
    95  Reuben Cummings

About Flask

Flask is a BSD-licensed microframework for Python based on Werkzeug, Jinja2 and good intentions.

License

AMZN Search API is distributed under the MIT License.