<
8000
path d="M8 9a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3ZM1.5 9a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3Zm13 0a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3Z">
@@ -1,8 +1,12 @@
1
1
ada-url
2
2
========
3
3
4
+ This is ``ada_url ``, a Python library for working with URLs based on the ``Ada `` URL
5
+ parser.
4
6
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/ >`__
6
10
7
11
Installation
8
12
------------
@@ -16,30 +20,20 @@ Install from `PyPI <https://pypi.org/project/ada-url/>`__:
16
20
Usage examples
17
21
--------------
18
22
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
+ ^^^^^^^^^^^^
21
25
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 >`_:.
33
28
34
29
.. code-block :: python
35
30
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'
41
35
42
- Parsing a URL:
36
+ The `` parse_url `` function returns a dictionary of all URL elements :
43
37
44
38
.. code-block :: python
45
39
@@ -61,19 +55,59 @@ Parsing a URL:
61
55
' scheme_type' : < SchemeType.HTTPS : 2 >
62
56
}
63
57
64
- Replacing URL components:
58
+ Altering URLs
59
+ ^^^^^^^^^^^^^
60
+
61
+ Replacing URL components with the ``URL `` class:
65
62
66
63
.. code-block :: python
67
64
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
+
68
73
>>> 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 '
71
76
72
- Joining a URL with a relative fragment:
77
+ Search parameters
78
+ ^^^^^^^^^^^^^^^^^
73
79
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'
77
111
78
112
WHATWG URL compliance
79
113
---------------------
@@ -100,10 +134,3 @@ Contrast that with the Python standard library's ``urlib.parse`` module:
100
134
' www.googlé.com'
101
135
>> > parsed_url.path
102
136
' /./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