This seems like the wrong place to be doing URL manipulation. The command line interface should be a thin layer (as thin as possible) on top of the Python API.