The API to get and set a file in a calibre book record is simply
# This will get the epub format for the book identified by id=book_id. The epub file will be copied to a temp file and the path to the temp file will be returned.
db.format(book_id, 'epub', index_is_id=True, as_path=True)
# This will set the epub format for the book record identified by book_id
stream = open(path_to_file, 'rb')
db.add_format(book_id, 'epub', stream, index_is_id=True)
For the rest of the plugin API, see the examples in this tutorial: http://manual.calibre-ebook.com/creating_plugins.html