Registry / serialization / pydantic-string-url

pydantic-string-url

JSON →
library1.0.2pypypi✓ verified 86d ago

Pydantic URL types based on str class for fast and simple URL validation. Current version 1.0.2, release cadence is low (semi-active maintenance). Provides Pydantic field types like HttpUrl, FtpUrl, etc., but unlike pydantic's own UrlStr, these are simple str subclasses that do not parse URL components.

pip install pydantic-string-url
INSTALL
IMPORT
SIG · PYDANTIC-STRING-UR
P
pydantic-string-url
serializationpythonv1.0.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

HttpUrl
from pydantic_string_url import HttpUrl
from pydantic import HttpUrl
pydantic's HttpUrl is different (UrlStr class). This library's HttpUrl is a str subclass with URL validation.
FtpUrl
from pydantic_string_url import FtpUrl
No common wrong import; just ensure correct module name.

Define a Pydantic model with URL fields. The URL types validate the string is a proper URL, but keep it as a plain string (not parsed into components).

from pydantic import BaseModel from pydantic_string_url import HttpUrl, FtpUrl class MyModel(BaseModel): website: HttpUrl ftp: FtpUrl # Valid m = MyModel(website='https://example.com', ftp='ftp://files.example.com') print(m.website) # 'https://example.com' # Invalid - raises ValidationError # m = MyModel(website='not-a-url', ftp='ftp://example.com')
Debug
Known issues
breakingTypes in this library are str subclasses, not UrlStr; use str() to get plain string if you need to disable subclass behavior.
fix
Use str(your_url_field) to get a plain string, or use .__str__() if needed for serialization.
affects: all
gotchaThis library's HttpUrl does NOT parse the URL into components like scheme, host, port. It only validates format. Use pydantic's HttpUrl if you need parsed access.
fix
If you need URL parsing (e.g., url.host), use from pydantic import HttpUrl instead of pydantic_string_url.
affects: all
Errors
Common errors & fixes
ImportError: cannot import name 'HttpUrl' from 'pydantic'
User imported HttpUrl from pydantic instead of pydantic_string_url. pydantic's HttpUrl exists but is different.
fix
Use 'from pydantic_string_url import HttpUrl' for this library's version. Or use 'from pydantic import HttpUrl' for pydantic's parsed URL type.
pydantic.error_wrappers.ValidationError: 1 validation error for MyModel website invalid or missing URL (type=value_error.url)
The URL string does not match the expected pattern (e.g., missing scheme or invalid format).
fix
Ensure URL starts with http://, https://, ftp://, etc. and conforms to standard URL format.
Upgrade
Version history
1.0.2latest on PyPI · released Sep 15, 2024
Audit
Dependencies
pydanticrequiredCore dependency; provides BaseModel and field validation
Agent activity
9 hits · last 30 days
node
8
Resources
pydantic-string-url — pip install pydantic-string-url · libregistry