Writing a query adapter

×

Status message

New Feature: Guest Login function added to facilitate site exploration without registering. Try it out!

Developing an adapter can be done completely offline from Araport. Once an adapter is running locally and the proper metadata is defined, the code should perform correctly in Adama.

Start a new Python virtual environment and a new git repository with:

mkdir my_adapter
cd my_adapter
git init
mkvirtualenv my_adapter

Write a Python module main.py, with a function search that takes a JSON object as argument in the form of a dictionary. Print JSON objects to standard output, separated by the characters "---".

For example:

# file: main.py

import json

def search(args):
    print json.dumps({'obj': 1, 'args': args})
    print "---"
    print json.dumps({'obj': 2, 'args': args})

This function can be tested in the Python interpreter:

$ python
Python 2.7.8 (default, Aug 24 2014, 21:26:19)
[GCC 4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.40)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import main
>>> main.search({'word1': 'hello', 'word2': 'world'})
{"args": {"word1": "hello", "word2": "world"}, "obj": 1}
---
{"args": {"word1": "hello", "word2": "world"}, "obj": 2}

Add the file main.py to the git repository with

git add main.py


Documentation Navigation