urlstd.parse.URLSearchParams#

class urlstd.parse.URLSearchParams(init: str)
class urlstd.parse.URLSearchParams(init: Sequence[Sequence[str | int | float]])
class urlstd.parse.URLSearchParams(init: dict[str, str | int | float])
class urlstd.parse.URLSearchParams(init: URLRecord)
class urlstd.parse.URLSearchParams(init: URLSearchParams)
class urlstd.parse.URLSearchParams

Bases: Collection

Parses and manipulates URL’s query.

Parameters:

init – One of: A string in application/x-www-form-urlencoded form, a sequence of name-value pairs, a dictionary containing name-value pairs, URLRecord object, or URLSearchParams object.

Examples

To create a URLSearchParams:

>>> params = URLSearchParams('?a=1&b=2&a=3')
>>> list(params)
[('a', '1'), ('b', '2'), ('a', '3')]
>>> params = URLSearchParams([('a', '1'), ('b', '2'), ('a', '3')])
>>> list(params)
[('a', '1'), ('b', '2'), ('a', '3')]
>>> params = URLSearchParams({'a': '1', 'b': '2', 'a': '3'})
>>> list(params)
[('a', '3'), ('b', '2')]
>>> new_params = URLSearchParams(params)
>>> list(new_params)
[('a', '3'), ('b', '2')]

Methods:

__add__(other)

Returns a string in application/x-www-form-urlencoded form concatenated with other.

__contains__(item)

Returns True if a name-value pair with the specified item exists, False otherwise.

__eq__(other)

Returns True if other is equal to this object.

__getitem__(key)

Returns the name-value pair(s) specified by key.

__iter__()

Returns a new iterator of this object’s items ((name, value) pairs).

__len__()

Returns the number of name-value pairs.

__str__()

Returns a string in application/x-www-form-urlencoded form.

append(name, value)

Appends a new name-value pair as a new search parameter.

attach(init)

Associates a URL record init with this URLSearchParams object.

delete(name[, value])

Removes all name-value pairs whose name is name and value is value.

entries()

Returns a new iterator of this object’s items ((name, value) pairs).

get(name)

Returns the value of the first name-value pair whose name is name.

get_all(name)

Returns the values of all name-value pairs whose name is name.

has(name[, value])

Returns True if a name-value pair with the specified name and value exists.

keys()

Returns a new iterator of this object’s names.

set(name, value)

If name-value pair with the specified name exists, sets the value of the first name-value pair whose name is name to value and remove the other values.

sort()

Sorts all name-value pairs by comparison of code units.

values()

Returns a new iterator of this object’s values.