URLObject is a utility class for manipulating URLs in Python. The latest version, 3.0.0, aims for a clearer API by focusing on explicit method names rather than relying heavily on operator overrides, building upon its predecessors. It provides an immutable object-oriented interface for parsing, constructing, and modifying URLs and their components. It is actively maintained with a recent release.
pip install urlobjectVerified import paths — ran on the pinned version, not inferred.
Demonstrates creating a URLObject, immutably modifying its components, accessing properties, and an example of handling authentication details using environment variables.
Review your code and replace operator overloads with explicit method calls as described in the library's documentation for version 3.x. For example, use `url.add_path('segment')` instead of `url + 'segment'`.Always assign the return value of modification methods to a variable: `my_new_url = original_url.with_scheme('https')`.Store sensitive credentials in environment variables and access them using `os.environ.get('YOUR_ENV_VAR', 'default_value')` when constructing URLs with authentication.Use the `join()` method for concatenating URL segments or other URLs: `URLObject('http://example.com/base').join('segment')`Use the `query_params` property to access query parameters (read-only dict) or `add_query_params()` to modify them: `url_obj.add_query_params({'param': 'value'})` or `print(url_obj.query_params.get('param'))`Use the `path_parts` property to get the path segments as a list, and `replace_path_parts()` to modify them: `url_obj.replace_path_parts(['new', 'path', 'segments'])` or `print(url_obj.path_parts)`
Import the `URLObject` class and call `parse` on it: `from urlobject import URLObject; URLObject.parse('http://example.com')`Add an import statement for the `URLObject` class at the beginning of your script: `from urlobject import URLObject`
No dependency data recorded yet.