Skip to content


Switch branches/tags

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time


Supported Python Versions pypi version Last commit Downloads Coverage

"Never trust user input!" is also true outside the security context: You cannot be sure users always provide you with valid and well formatted data.

The Python package userprovided checks input for validity and / or plausibility. Besides that it contains some methods to convert input into standardized formats.

The code has type hints (PEP 484) and aims to provide useful log and error messages.

Userprovided has functionality for the following inputs:

  • parameters:
    • Check a dictionary for valid, needed, and unknown keys.
    • Convert lists, strings and tuples into a set
    • Check if an integer or string is in a specific range.
    • ...
  • url:
  • hash:
    • Is the hash method available?
    • Calculate a file hash and (optionally) compare it to an expected value.
  • date:
    • Does a given date exist?
    • Convert English and German long format dates to ISO strings.
  • mail:
    • Check if a string is a valid email address.


Install exoskeleton using pip or pip3. For example:

sudo pip3 install userprovided

You may consider using a virtualenv.

To upgrade to the latest version accordingly:

sudo pip install userprovided --upgrade

Handle Parameters

Check a Parameter Dictionary

If your application accepts parameters in the form of a dictionary, you have to test if all needed parameters are provided and if there are any unknown keys (maybe due to typos). There is a method for that:

    dict_to_check = {'a': 1, 'b': 2, 'c': 3},
    allowed_keys = {'a', 'b', 'c', 'd'},
    necessary_keys = {'b', 'c'})

Returns True if the dictionary dict_to_check contains only allowed keys and all necessary keys are present.

Avoid Keys without Value in a Dictionary

Check if all keys in a dictionary have a value. Return False if the value for any key is empty. Works for strings (including whitespace only), dictionary, list, tuple, and set.

# returns True:
parameters.keys_neither_none_nor_empty({'a': 123, 'b': 'example'})

# returns False:
parameters.keys_neither_none_nor_empty({'a': '   ', 'b': 'example'})
parameters.keys_neither_none_nor_empty({'a': None, 'b': 'example'})
parameters.keys_neither_none_nor_empty({'a': list(), 'b': 'example'})

Convert into a set

Convert a string, a tuple, or a list into a set (i.e. no duplicates, unordered):


Check Range of Numbers and Strings

def numeric_in_range(parameter_name,
                     fallback_value) -> Union[int, float]

def string_in_range(string_to_check,
                    strip_string: bool = True) -> bool

# Checks if the port is integer and within the
# valid range from 0 to 65535.

Handle URLs

Normalize URLs

Normalize an URL means:

  • remove whitespace around it,
  • convert scheme and hostname to lowercase,
  • remove ports if they are the standard port for the scheme,
  • remove duplicate slashes from the path,
  • remove fragments (like #foo),
  • remove empty elements of the query part,
  • order the elements in the query part by alphabet

The optional parameter drop_keys allows you to remove specific keys, like session ids or trackers, from the query part of the URL.

url = ''
# returns:
userprovided.url.normalize_url(url, drop_keys=['c'])
# returns:

Check URLs

To check whether a string is a valid URL - including a scheme (like https) - use userprovided.url.is_url.

# => True
# => False

You can insist on a specific scheme:

userprovided.url.is_url('', ('ftp'))
# => False (Schema does not match permitted)

userprovided.url.is_url('', ('ftp'))
# => True

Determine a File Extension

Guess the correct filename extension from an URL and / or the mime-type returned by the server. Sometimes a valid URL does not contain a file extension (like, or it is ambiguous. So the mime type acts as a fallback. In case the correct extension cannot be determined at all, it is set to 'unknown'.

# retuns '.html'

# retuns '.pdf'

Check Email Addresses

# => False

# => True

File Hashes

You can check whether a specific hash method is available. This will raise a ValueError for MD5 and SHA1 even if they are available, because they are deprecated.

# => ValueError because md5 is deprecated

# => True on almost any system

You can calculate hash sums for files. If you do not provide the method, this defaults to SHA256. Other supported methods are SHA224 and SHA512.

# returns the hash of the file as a string:

If you provide an expected value for the hash you can check for file changes or tampering. In the case the provided value and the calculated hash do not match, a ValueError exception is raised.

    file_path = pathlib.Path('./foo.txt'),
    hash_method = 'sha512',
    expected_hash = 'not_the_right_value')
# => raises an exception

Handle Calendar Dates

Does a specific date exist?, 2, 31)
# => False

Normalize German or English long form dates :'October 3, 1990')
# => '1990-10-03''3. Oktober 1990')
# => '1990-10-03'

Update and Deprecation Policy

  • No breaking changes in micro-versions.
  • It makes no sense to duplicate functionality already available in the Python Standard Library. Therefore, if this package contains functionality that becomes superseded by the Standard Library, it will start to log a depreciation warning. The functionality itself is planned to stay available for at least a major version of userprovided and as long as Python versions not containing this functionality are supported.


A Python package to check input for validity and / or plausibility. Also contained: some methods to convert input into standardized formats.








No packages published