url¶
validators.url.url(value, /, *, skip_ipv6_addr=False, skip_ipv4_addr=False, may_have_port=True, simple_host=False, strict_query=True, rfc_1034=False, rfc_2782=False)
¶
Return whether or not given value is a valid URL.
This validator was inspired from URL validator of dperini. The following diagram is from urlly.
foo://admin:hunter1@example.com:8042/over/there?name=ferret#nose
\_/ \___/ \_____/ \_________/ \__/\_________/ \_________/ \__/
| | | | | | | |
scheme username password hostname port path query fragment
Examples:
>>> url('http://duck.com')
# Output: True
>>> url('ftp://foobar.dk')
# Output: True
>>> url('http://10.0.0.1')
# Output: True
>>> url('http://example.com/">user@example.com')
# Output: ValidationError(func=url, ...)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
str
|
URL string to validate. |
required |
skip_ipv6_addr |
bool
|
When URL string cannot contain an IPv6 address. |
False
|
skip_ipv4_addr |
bool
|
When URL string cannot contain an IPv4 address. |
False
|
may_have_port |
bool
|
URL string may contain port number. |
True
|
simple_host |
bool
|
URL string maybe only hyphens and alpha-numerals. |
False
|
strict_query |
bool
|
Fail validation on query string parsing error. |
True
|
rfc_1034 |
bool
|
Allow trailing dot in domain/host name. Ref: RFC 1034. |
False
|
rfc_2782 |
bool
|
Domain/Host name is of type service record. Ref: RFC 2782. |
False
|
Returns:
Type | Description |
---|---|
Literal[True]
|
If |
ValidationError
|
If |
Note
- In version 0.11.3:
- Added support for URLs containing localhost.
- In version 0.11.0:
- Made the regular expression case insensitive.
- In version 0.10.3:
- Added a
public
parameter.
- Added a
- In version 0.10.2:
- Added support for various exotic URLs.
- Fixed various false positives.
New in version 0.2.0.
Source code in /opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/validators/url.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
|