You can use urlparse() in urllib (from urllib.parse import urlparse). If the string starts with a protocol, then, the returned dict contains a scheme.