We will be building an application to retrieve and store documents. We will implement an access library/module, several servers, and several clients.
The document store is an SQLite relational database. It is file based.
The document store will contain the following information:
There is a sample database containing a few documents (records) in ./Data/documents01.sqlite.
You can create a new, empty database by running create_doc_database.py.
Here are some SQL queries that you will find useful:
# Get and update config (latest_id). sql = 'select latest_id from config' sql = 'update config set latest_id={}'.format(new_id) # # Get id, tags, and description for all documents. sql = 'select id, tags, description from documents' # # Get all fields for a specific document by ID. sql = 'select * from documents where id = {}'.format(id) # # Insert a new document into the database. sql = 'insert into documents values ({}, "{}", "{}", "{}")'.format( new_id, tags, description, body)
More information about SQLite: http://www.sqlite.org/docs.html
Now, do each of the following:
Implement a module/library to access and add records to a document repository stored in a SQLite relational file/database. Support the following API:
The file create_doc_database.py can be used to create and initialize a new empty SQLite document database file.
Implement a REST-ful document server. Build your server on ZeroMQ.
Your document server should provide these capabilities:
You can find templates for the ZeroMQ parts in Templates/hwserver.py and Templates/hwclient.py
Implement a ZeroMQ client for your document server. The client should be able to perform these functions:
Implement a command line shell as a client for the document store. Use the cmd module from the standard Python library. Your command line shell can either (1) access your library/module directly or (2) use your ZeroMQ client.
In your command line shell, implement the same commands: list, search, get, and add.
Optional task -- Use one of the Python command line parsers (getopt or argparse) to parse the command line passed into this program. Implement support for options "-v", "--verbose", "-h", and "--help".
Implement a Web application server that provides access to the documents in our document store. Build your Web application with Pyramid.
Your Web application server should support these operations (URLs):
/help -- Show this help. /list -- List all documents. /search/{tag} -- Search for and show documents by tag. /get/{id} -- Get and show document by ID.
You can create a starter Pyramid application with the following commands:
$ pcreate --help $ pcreate --list $ pcreate --scaffold=starter my_doc_server $ cd my_doc_server $ python setup.py develop
Now start the server with the following:
$ pserve development.ini
Then visit http://localhost:6543 in your Web browser to see whether your application is good.