A library to check user input for validity and / or plausibility
Project description
userprovided
The package "userprovided" checks input for validity and / or plausibility. For example it can check whether a string is a valid email address or an URL. It can do more complicated tasks like checking a dictionary for valid and needed keys. It also contains some functionalities to convert input into a more rigid format (like the string 'October 3, 1990' into '1990-10-03').
There are plenty of validators out there. The reasons to write another one:
- Its sister-project exoskeleton needs some special features.
- Extensive testing (100% test coverage / unit tests / automatic test generation with the hypothesis package)
- The code has type hints (PEP 484)
- Modularity
Update and Deprecation Policy
The development status of "userprovided" is "beta":
- Despite rigorous testing it might still contain some bugs.
- Some commands could change with one of the next releases. If possible function parameters will be kept unchanged. Sometimes optional parameters can be added to existing functions.
It makes no sense to duplicate functionality already available in the Python Standard Library. There is for example no function to check IP addresses as the library ipaddress is part of the standard (since Python 3.3.).
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.
Installation and Use
Install exoskeleton using pip or pip3. For example:
sudo pip install userprovided
You may consider using a virtualenv.
To upgrade to the latest version accordingly:
sudo pip install userprovided --upgrade
Examples / Available Functions
#!/usr/bin/env python3
import userprovided
### Cloud ###
userprovided.cloud.is_aws_s3_bucket_name('foobar')
# => True
### Dates ###
userprovided.date.date_exists(2020, 2, 31)
# => false
userprovided.date.date_en_long_to_iso('October 3, 1990')
# => '1990-10-03'
### Hashes ###
print(userprovided.hash.hash_available('md5'))
# => ValueError because md5 is deprecated
print(userprovided.hash.hash_available('sha256'))
# => True on almost any system
userprovided.hash.calculate_file_hash(pathlib.Path('./foo.txt'))
# Defaults to SHA256 and returns the hash of the file as a string.
# Also supports SHA224 and SHA512.
### Mailadresses ###
userprovided.mail.is_email(None)
# => False
userprovided.mail.is_email('example@example.com')
# => True
### Parameters ###
userprovided.parameters.convert_to_set(list)
# => Convert a string, a tuple, or a list into a set
# (i.e. no duplicates, unordered)
userprovided.parameters.validate_dict_keys(
dict_to_check = {'a': 1, 'b': 2, 'c': 3},
allowed_keys = {'a', 'b', 'c', 'd'},
necessary_keys = {'b', 'c'})
# => True
# The dictionary contains only allowed keys and
# all necessary keys are present.
### Ports ###
userprovided.port.port_in_range(int)
# Checks if the port is integer and within the
# valid range from 0 to 65536.
### URLs ###
print(userprovided.url.is_url('https://www.example.com'))
# => True
print(userprovided.url.is_url('https://www.example.com', ('ftp')))
# => False (Schema does not match permitted)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file userprovided-0.7.1.tar.gz.
File metadata
- Download URL: userprovided-0.7.1.tar.gz
- Upload date:
- Size: 7.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.6.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
65275b9d92723c6b47b975fdad662c3842f0f98a9d2f868f4bbd060227e50666
|
|
| MD5 |
8e04154fb7db898f213e233ce4d935f4
|
|
| BLAKE2b-256 |
51c75937a30e1e1454daf3b46c5b962b4da011c8a39164709f0c20a90326952a
|
File details
Details for the file userprovided-0.7.1-py3-none-any.whl.
File metadata
- Download URL: userprovided-0.7.1-py3-none-any.whl
- Upload date:
- Size: 13.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.6.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aeb9ea7119106b58366cadd01eaebfc4305fde2ca91e156a562cc89a54296eb4
|
|
| MD5 |
679fe4152380b1d57b100bf19d3214a3
|
|
| BLAKE2b-256 |
f66f7be9df3a92d85dbcc09b115c11bed9b685581967b18afd990d50d6c8086d
|