If you want to use Python to quickly build a URL using information such as scheme, host, port, path, query, fragment, etc, try yarl.
yarl also makes it easy to replace one part with another, such as a query.
Link to yarl.
My previous tips on feature extraction.