url¶
validators.url.url(value, /, *, skip_ipv6_addr=False, skip_ipv4_addr=False, may_have_port=True, simple_host=False, strict_query=True, consider_tld=False, private=None, rfc_1034=False, rfc_2782=False)
¶
Return whether or not given value is a valid URL.
This validator was originally 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
|
consider_tld |
bool
|
Restrict domain to TLDs allowed by IANA. |
False
|
private |
Optional[bool]
|
Embedded IP address is public if |
None
|
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 |
Source code in src/validators/url.py
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 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
|