_regex.py (contains compiled regex FOR INTERNAL USAGE ONLY)
Plus a secondary package tests which includes several submodules.
Specifically one for each test suite and named according to the api to test (eg. tests for is_ip()
will be in test_is_ip.py and so on).
All the public API are importable directly from the main package string_utils, so this:
from string_utils.validation import is_ip
can be simplified as:
from string_utils import is_ip
Api overview
Bear in mind: this is just an overview,
for the full API documentation see:readthedocs.io
is_credit_card: Checks if the given string is a credit card
is_credit_card(value)
# returns true if `value` represents a valid card number for one of these:
# VISA, MASTERCARD, AMERICAN EXPRESS, DINERS CLUB, DISCOVER or JCB
is_camel_case: Checks if the given string is formatted as camel case
prettify: Reformat a string by applying basic grammar and formatting rules
prettify(' unprettified string ,, like this one,will be"prettified" .it\' s awesome! ')
# the ouput will be: 'Unprettified string, like this one, will be "prettified". It\'s awesome!'
asciify: Converts all non-ascii chars contained in a string into the closest possible ascii representation
asciify('èéùúòóäåëýñÅÀÁÇÌÍÑÓË')
# returns 'eeuuooaaeynAAACIINOE' (string is deliberately dumb in order to show char conversion)
slugify: Convert a string into a formatted "slug"
slugify('Top 10 Reasons To Love Dogs!!!') # returns: 'top-10-reasons-to-love-dogs'
booleanize: Convert a string into a boolean based on its content
roman_encode: Encode integers/string into roman numbers
roman_encode(37) # returns 'XXXVII'
roman_decode: Decode roman number into an integer
roman_decode('XXXVII') # returns 37
roman_range: Generator which returns roman numbers on each iteration
for n in roman_range(10): print(n) # prints: I, II, III, IV, V, VI, VII, VIII, IX, X
for n in roman_range(start=7, stop=1, step=-1): print(n) # prints: VII, VI, V, IV, III, II, I
String generations:
uuid: Returns the string representation of a newly created UUID object
uuid() # possible output: 'ce2cd4ee-83de-46f6-a054-5ee4ddae1582'
uuid(as_hex=True) # possible output: 'ce2cd4ee83de46f6a0545ee4ddae1582'
random_string: Creates a string of the specified size with random chars
random_string(9) # possible output: 'K1URtlTu5'
secure_random_hex: Creates an hexadecimal string using a secure strong random generator
secure_random_hex(12)
# possible ouput: 'd1eedff4033a2e9867c37ded'
# (len is 24, because 12 represents the number of random bytes generated, which are then converted to hexadecimal value)
Installation
pip install python-string-utils
Checking installed version
import string_utils
string_utils.__version__
'1.0.0' # (if '1.0.0' is the installed version)
Do you like this project? Would you like to see it updated more often with new features and improvements?
If so, you can make a small donation by clicking the button down below, it would be really appreciated! :)