### Install Package and Run Tests Source: https://github.com/ada-url/ada-python/blob/main/docs/index.rst Installs the built Ada-Python package in editable mode and runs the unit tests. ```sh python -m pip install -e . python -m unittest ``` -------------------------------- ### Install ada-url using pip Source: https://github.com/ada-url/ada-python/blob/main/README.rst Installs the ada-url library from PyPI using the pip package installer. This is the standard method for adding Python packages to your environment. ```sh pip install ada_url ``` -------------------------------- ### Install Development Requirements and Build Package Source: https://github.com/ada-url/ada-python/blob/main/docs/index.rst Installs necessary development dependencies from 'requirements/development.txt' and builds the Ada-Python package without isolation. ```sh python -m pip install -r requirements/development.txt python -m build --no-isolation ``` -------------------------------- ### Modify URL components using URL class Source: https://github.com/ada-url/ada-python/blob/main/README.rst Shows how to modify specific components of a URL object created with the `URL` class. This example demonstrates changing the host of a URL and accessing the updated `href`. ```Python from ada_url import URL >>> urlobj = URL('https://example.org/path/../file.txt') >>> urlobj.host = 'example.com' >>> urlobj.href 'https://example.com/file.txt' ``` -------------------------------- ### Clone Ada-Python Repository Source: https://github.com/ada-url/ada-python/blob/main/docs/index.rst Clones the Ada-Python git repository to a local directory for development. ```sh git clone https://github.com/ada-url/ada-python.git ada_url_python cd ada_url_python ``` -------------------------------- ### Create and Activate Virtual Environment Source: https://github.com/ada-url/ada-python/blob/main/docs/index.rst Creates a Python virtual environment named 'env' and activates it for building and development. ```sh python3 -m venv env source ./env/bin/activate ``` -------------------------------- ### WHATWG URL compliance: IDNA encoding and path resolution Source: https://github.com/ada-url/ada-python/blob/main/README.rst Highlights the library's adherence to the WHATWG URL specification, specifically showcasing how it correctly encodes IDNs and resolves relative path segments in URLs. ```Python from ada_url import URL >>> parsed_url = URL('https://www.GOoglé.com/./path/../path2/') >>> parsed_url.hostname 'www.xn--googl-fsa.com' >>> parsed_url.pathname '/path2/' ``` -------------------------------- ### Work with URL search parameters using URLSearchParams Source: https://github.com/ada-url/ada-python/blob/main/README.rst Illustrates the usage of the `URLSearchParams` class for handling query string parameters. It shows how to parse a query string and iterate over its key-value pairs. ```Python from ada_url import URLSearchParams >>> obj = URLSearchParams('key1=value1&key2=value2') >>> list(obj.items()) [('key1', 'value1'), ('key2', 'value2')] ``` -------------------------------- ### Comparison with urllib.parse for URL handling Source: https://github.com/ada-url/ada-python/blob/main/README.rst Contrasts the behavior of `ada-url` with Python's standard `urllib.parse` module, particularly regarding IDN handling and path resolution, illustrating `ada-url`'s compliance with modern URL standards. ```Python from urllib.parse import urlparse >>> parsed_url = urlparse('https://www.GOoglé.com/./path/../path2/') >>> parsed_url.hostname 'www.googlé.com' >>> parsed_url.path '/./path/../path2/' ``` -------------------------------- ### Parse and normalize URLs with URL class Source: https://github.com/ada-url/ada-python/blob/main/README.rst Demonstrates parsing a URL string using the `URL` class from the `ada_url` library. It shows how the library normalizes the URL, resolving relative paths like '../'. ```Python from ada_url import URL >>> urlobj = URL('https://example.org/path/../file.txt') >>> urlobj.href 'https://example.org/path/file.txt' ``` -------------------------------- ### Encode and decode Internationalized Domain Names (IDNs) Source: https://github.com/ada-url/ada-python/blob/main/README.rst Demonstrates the `idna` class functionality for encoding and decoding Internationalized Domain Names (IDNs). This allows for proper handling of domain names with non-ASCII characters. ```Python from ada_url import idna >>> idna.encode('Bücher.example') b'xn--bcher-kva.example' >>> idna.decode(b'xn--bcher-kva.example') 'bücher.example' ``` -------------------------------- ### Deactivate Virtual Environment Source: https://github.com/ada-url/ada-python/blob/main/docs/index.rst Exits the currently active Python virtual environment. ```sh deactivate ``` -------------------------------- ### Parse URL into components with parse_url Source: https://github.com/ada-url/ada-python/blob/main/README.rst Utilizes the `parse_url` function to break down a URL string into its constituent parts, returning a dictionary of all components including username, password, protocol, hostname, path, query, and fragment. ```Python from ada_url import parse_url >>> parse_url('https://user:pass@example.org:80/api?q=1#2') { 'href': 'https://user:pass@example.org:80/api?q=1#2', 'username': 'user', 'password': 'pass', 'protocol': 'https:', 'port': '80', 'hostname': 'example.org', 'host': 'example.org:80', 'pathname': '/api', 'search': '?q=1', 'hash': '#2', 'origin': 'https://example.org:80', 'host_type': , 'scheme_type': } ``` -------------------------------- ### Replace URL components with replace_url function Source: https://github.com/ada-url/ada-python/blob/main/README.rst Demonstrates using the `replace_url` function to create a new URL string with specified components replaced. This provides a functional approach to URL modification. ```Python from ada_url import replace_url >>> replace_url('https://example.org/path/../file.txt', host='example.com') 'https://example.com/file.txt' ``` -------------------------------- ### Parse search parameters into a dictionary with parse_search_params Source: https://github.com/ada-url/ada-python/blob/main/README.rst Uses the `parse_search_params` function to convert a URL query string into a dictionary where keys map to lists of values. This is useful for handling URLs with repeated query parameters. ```Python from ada_url import parse_search_params >>> parse_search_params('key1=value1&key2=value2') {'key1': ['value1'], 'key2': ['value2']} ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.