http://manual.calibre-ebook.com/conv...l#introduction
http://manual.calibre-ebook.com/deve...ml#code-layout
For input all you will need to do is unzip and possibly convert any kepub specific features into their epub equivalents and return the path to the opf file.
For output, you will need to do the following (in outline)
1) Transform the markup to conform to kepub (add the span tags used for annotations, etc.)
1.5) Do various bits of epub specific processing like covers and so on, as is done in the epub output plugin.
2) Output to disk using the oeb writer as is done in the epub output plugin
3) zip up the files, again as is done in the epub output plugin
You can subclass the epub output plugin and re-use various bits of code from it. If you need some refactoring to make the code more re-usable, let me know.