11ada-url
22========
33
4+ This is ``ada_url ``, a Python library for working with URLs based on the ``Ada `` URL
5+ parser.
46
5- This is ``ada_url ``, a Python library for parsing and joining URLs.
7+ * `Documentation <https://ada-url.readthedocs.io >`__
8+ * `Development <https://github.com/ada-url/ada-python/ >`__
9+ * `Ada <https://www.ada-url.com/ >`__
610
711Installation
812------------
@@ -16,30 +20,20 @@ Install from `PyPI <https://pypi.org/project/ada-url/>`__:
1620 Usage examples
1721--------------
1822
19- This package exposes a `` URL `` class that is intended to match the one described in the
20- ` WHATWG URL spec < https://url.spec.whatwg.org/#url-class >`__.
23+ Parsing URLs
24+ ^^^^^^^^^^^^
2125
22- .. code-block :: python
23-
24- >> > from ada_url import URL
25- >> > URL(' https://example.org/path/../file.txt' ) as urlobj:
26- >> > urlobj.host = ' example.com'
27- >> > new_url = urlobj.href
28- >> > new_url
29- ' https://example.com/file.txt'
30-
31- It also provides high level functions for parsing and manipulating URLs. Validating
32- a URL:
26+ The ``URL `` class is intended to match the one described in the
27+ `WHATWG URL spec <https://url.spec.whatwg.org/#url-class >`_:.
3328
3429.. code-block :: python
3530
36- >> > from ada_url import check_url
37- >> > check_url(' https://example.org' )
38- True
39- >> > check_url(' http://example:bougus' )
40- False
31+ >> > from ada_url import URL
32+ >> > urlobj = URL(' https://example.org/path/../file.txt' )
33+ >> > urlobj.href
34+ ' https://example.org/path/file.txt'
4135
42- Parsing a URL:
36+ The `` parse_url `` function returns a dictionary of all URL elements :
4337
4438.. code-block :: python
4539
@@ -61,19 +55,59 @@ Parsing a URL:
6155 ' scheme_type' : < SchemeType.HTTPS : 2 >
6256 }
6357
64- Replacing URL components:
58+ Altering URLs
59+ ^^^^^^^^^^^^^
60+
61+ Replacing URL components with the ``URL `` class:
6562
6663.. code-block :: python
6764
65+ >> > from ada_url import URL
66+ >> > urlobj = URL(' https://example.org/path/../file.txt' )
67+ >> > urlobj.host = ' example.com'
68+ >> > urlobj.href
69+ ' https://example.com/path/file.txt'
70+
71+ Replacing URL components with the ``replace_url `` function:
72+
6873 >>> from ada_url import replace_url
69- >> > ada_url. replace_url(' http ://example.org:80 ' , protocol = ' https: ' )
70- ' https://example.org/ '
74+ >>> replace_url(' https ://example.org/path/../file.txt ' , host = ' example.com ' )
75+ 'https://example.com/file.txt '
7176
72- Joining a URL with a relative fragment:
77+ Search parameters
78+ ^^^^^^^^^^^^^^^^^
7379
74- >>> from ada_url import join_url
75- >>> join_url(' https://example.org/dir/child.txt' , ' ../parent.txt' )
76- 'https://example.org/parent.txt'
80+ The ``URLSearchParams `` class is intended to match the one described in the
81+ `WHATWG URL spec <https://url.spec.whatwg.org/#interface-urlsearchparams >`__.
82+
83+ .. code-block :: python
84+
85+ >> > from ada_url import URLSearchParams
86+ >> > obj = URLSearchParams(' key1=value1&key2=value2' )
87+ >> > list (obj.items())
88+ [(' key1' , ' value1' ), (' key2' , ' value2' )]
89+
90+ The ``parse_search_params `` function returns a dictionary of search keys mapped to
91+ value lists:
92+
93+ .. code-block :: python
94+
95+ >> > from ada_url import parse_search_params
96+ >> > parse_search_params(' key1=value1&key2=value2' )
97+ {' key1' : [' value1' ], ' key2' : [' value2' ]}
98+
99+ Internationalized domain names
100+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
101+
102+ The ``idna `` class can encode and decode IDNs:
103+
104+ .. code-block :: python
105+
106+ >> > from ada_url import idna
107+ >> > idna.encode(' Bücher.example' )
108+ b ' xn--bcher-kva.example'
109+ >> > idna.decode(b ' xn--bcher-kva.example' )
110+ ' bücher.example'
77111
78112 WHATWG URL compliance
79113---------------------
@@ -100,10 +134,3 @@ Contrast that with the Python standard library's ``urlib.parse`` module:
100134 ' www.googlé.com'
101135 >> > parsed_url.path
102136 ' /./path/../path2/'
103-
104- More information
105- ----------------
106-
107- * ``ada-url `` is based on the `Ada <https://www.ada-url.com/ >`__ project.
108- * A full API reference is available at `Read the Docs <https://ada-url.readthedocs.io >`__.
109- * Source code is available at `GitHub <https://github.com/ada-url/ada-python >`__.
0 commit comments