Skip to main content

Logo

stringtools provides string operations, such as analaysing, converting, generating, validating.

Tests Downloads Quality Supported Python versions

Analysis


Source Code: https://github.com/Vazno/stringtools

PyPI: https://pypi.org/project/stringtools/


stringtools has a lot of solutions specially built to be fast and stable ⚡.

The key features are:

  • Easy to use: It has friendly and well-commented code.
  • Open source: stringtools is completely free and open source
  • Stability: Most of the code is covered with tests, so there is a less chance to catch a bug.

Installation:

pip install stringtools

User’s Guide:

There are 5 categories:

analaysers - Analyse string.

is_pangram is_heterogram is_anagram is_palindrome
is_tautogram Spelling

converters - Convert one string value to other string value.

bricks replaceall numerate_text remove_trailing_whitespaces
remove_leading_whitespaces text_to_binary binary_to_text str_to_bool

general - General string operations.

Cases Morse

generators - Generate text inforamation.

Nick Password LoremIpsum

validators - Validate ip, email addresses, e.t.c

validate_semver validate_email validate_ipv4 validate_ipv6
validate_url

Usage/Examples

analaysers:

from stringtools.analysers import *

is_pangram()

↑ Checks if inputed string is pangram (A pangram is a sentence using every letter of a given alphabet at least once.)

is_pangram('Watch "Jeopardy!", Alex Trebek\'s fun TV quiz game.') 
# -> True
is_pangram('Hello beautiful world!') 
# -> False

is_heterogram()

↑ Checks if inputed string is heterogram (A heterogram is a string in which no letter of the alphabet occurs more than once.)

is_heterogram("abcd")
# -> True
is_heterogram("abcdd")
# -> False

is_anagram()

↑ Checks if inputed string is an anagram (Anagram is a string that contain all letters from other string.)

is_anagram("Tom Marvolo Riddle", "I Am Lord Voldemort")
# -> True
is_anagram("God", "Good")
# -> False

is_palindrome()

↑ Checks if inputed string is a palindrome (A palindrome is a word, number, phrase, or other sequence of characters which reads the same backward as forward, such as madam or racecar.)

is_palindrome(["r","a","d","a","r"])
# -> True
is_palindrome(123)
# -> False

is_tautogram()

↑ Checks if inputed string is a tautogram (A tautogram is a text in which all words start with the same letter.)

is_tautogram("Crazy cat, cute, cuddly")
# -> True
is_tautogram("Crazy mouse, cute, cuddly")
# -> False

Spelling

↑ Spell checker, which works by using levenshtein() function, can give correction suggestions, tell if a word is legit.

s = Spelling("en")
s.is_correct("Hello")
# -> True
s.is_correct("eagoapesaf")
# -> False
s.get_suggestions("toxicit", 2)
# -> ['toxicity', 'solicit']

converters:

from stringtools.converters import *

bricks()

↑ Returns bricked version of a string.

bricks("Hello world!")
# -> "HeLlO WoRlD!
bricks("abcdef")
# -> "AbCdEf"

replaceall()

↑ Replaces text from given sentence and dictionary.

dictionary should be formatted like this:

{"old_string": "new_string"}
replaceall("12345", {"1": "One ", "2": "Two ", "3": "Three "})
# -> "One Two Three 45"
replaceall("Hello world!", {"Hello": "Sup", "world": "earth"})
# -> "Sup earth!"

numerate_text()

↑ Numerate each line of text.

numerate_text("Hello world\nHow are you doing?")
# -> "1 Hello World\\n2 How are you doing?"
numerate_text("First line.\nThe second line\nThe third line")
# -> "1 First line.\n2 The second line\n3 The third line"

remove_trailing_whitespaces()

↑ Remove all trailing whitespaces from sentence.

remove_trailing_whitespaces("text   ")
# -> "text"
remove_trailing_whitespaces("Look at this. ")
# -> "Look at this."'''

remove_leading_whitespaces()

↑ Remove all leading whitespaces from sentence.

remove_leading_whitespaces("   text")
# -> "text"
remove_leading_whitespaces(" Look at this.")
# -> "Look at this."'''

text_to_binary()

↑ Convert string to a binary (A binary number is a number expressed in the base-2 numeral system or binary numeral system, a method of mathematical expression which uses only two symbols: 0 and 1)

text_to_binary("Hello")
# -> 0100100001100101011011000110110001101111
text_to_binary("A")
# -> 01000001

binary_to_text()

↑ Convert binary to text (A binary number is a number expressed in the base-2 numeral system or binary numeral system, a method of mathematical expression which uses only two symbols: 0 and 1)

binary_to_text("0100100001100101011011000110110001101111")
# -> "Hello"
binary_to_text("01000001")
# -> "A"'''

str_to_bool()

↑ Converts a string representation of truth to bool

False values are: "False", "f", "no", "n", "off", "0"
True values are: "True", "t", "yes", "y", "on", "1"
str_to_bool("True")
# -> True
str_to_bool("False")
# -> False

general:

from stringtools.general import *

Cases()

↑ Convert strings (and dictionary keys) between cases, and analyse.

Converting strings
Cases.camelize("jack_in_the_box")
# -> "jackInTheBox"
Cases.decamelize("rubyTuesdays")
# -> "ruby_tuesdays"
Cases.pascalize("red_robin")
# -> "RedRobin"
Cases.kebabize("white_castle")
# -> "white-castle"
Converting dictionary keys
array = [{"attrOne": "foo"}, {"attrOne": "bar"}]
Cases.decamelize(array)
# -> [{"attr_one": "foo"}, {"attr_one": "bar"}]

array = [{"attr_one": "foo"}, {"attr_one": "bar"}]
Cases.camelize(array)
# -> [{"attrOne": "foo"}, {"attrOne": "bar"}]

array = [{'attr_one': 'foo'}, {'attr_one': 'bar'}]
Cases.kebabize(array)
# -> [{'attr-one': 'foo'}, {'attr-one': 'bar'}]

array = [{"attr_one": "foo"}, {"attr_one": "bar"}]
Cases.pascalize(array)
# -> [{"AttrOne": "foo"}, {"AttrOne": "bar"}]
Checking character casing
Cases.is_camelcase("illWearYourGranddadsClothes")
# -> True
Cases.is_pascalcase("ILookIncredible")
# -> True
Cases.is_snakecase("im_in_this_big_coat")
# -> True
Cases.is_kebabcase('from-that-shop')
# -> True
Cases.is_camelcase("from_that_shop")
# -> False
Cases.is_snakecase("downTheRoad")
# -> False
Cases.is_kebabcase('from_that_shop')
# -> False

# what about abbrevations, acronyms, and initialisms? No problem!
Cases.decamelize("APIResponse")
# -> "api_response"

Morse()

↑ Convert sentence to morse code, and vice versa.

print(Morse.encode("HELLO, WORLD!"))
# -> ".... . .-.. .-.. --- --..-- / .-- --- .-. .-.. -.. -.-.--"
print(Morse.decode(".... . .-.. .-.. --- --..-- / .-- --- .-. .-.. -.. -.-.--"))
# -> "HELLO, WORLD!"

generators:

from stringtools.generators import *

Nick()

↑ Generate nicknames by inputed vowels, consonants, and other sounds.

n = Nick()
n.set_length(5)
for i in range(20):
    print(n.generate())
# -> 
# "Irrol"
# "Uppuq"
# "Aguir"
# "Moury"
# "Uwrax"
# "Ezeoa"
# "Agaum"
# "Egeti"
# "Efuyu"
# "Iruek"
# "Qawze"
# "Oguei"
# "Hochu"
# "Maqod"
# "Suyff"
# "Idoor"
# "Keigh"
# "Uredi"
# "Eceuy"
# "Elere"

Password()

↑ Generate very strong passwords.

You can choose these options for password:
  • English (abcd...)
  • Numerals (1234...)
  • Special Symbols ('`<*...)
  • Own symbols (Any)
  • Exclude similar characters (1, l, L, 0, o, O, etc.)
p = Password()
p.set_length(8)
p.add_symbols()
p.add_digits()
p.add_ascii_letters()
p.generate()
# -> "C-3?r#$a"
p = Password()
p.set_length(16)
p.add_own("123")
# -> "3312311232131231"
print(Password.is_strong("123456789qwerty"))
# -> False
print(Password.is_strong("Aa0D#4v17@13.-0"))
# -> True

LoremIpsum()

↑ Generate Lorem Ipsum text. (Lorem ipsum is a placeholder text commonly used to demonstrate the visual form of a document or a typeface without relying on meaningful content.)

x = LoremIpsum()
x.set_length(5)
x.set_word_randrange((4, 10))
print(x.generate())
# -> "Lorem ipsum etnnimouft orknore zeoozeea."
print(x.generate())
# -> "Lorem ipsum eodyr gueipnaive pnaiz."

validators:

from stringtools.validators import *

Validator.validate_semver()

↑ Validate if version name follows semantic versioning. For more information go to: https://semver.org/

Validator.validate_semver("1.0.0")
# -> True
Validator.validate_semver("1.0.0.0")
# -> False

Validator.validate_email()

↑ Validate an email address.

Validator.validate_email("email@example.com")
# -> True
Validator.validate_email("email@example..com")
# -> False

Validator.validate_url()

↑ Validate url address.

Validator.validate_url("https://example.com/")
# -> True
Validator.validate_url("example.com")
# -> False

Validator.validate_ipv4()

↑ Validate an ipv4 address.

Validator.validate_ipv4("127.255.255.254")
# -> True
Validator.validate_ipv4("127.255.254")
# -> False

Validator.validate_ipv6()

↑ Validate an ipv6 address.

Validator.validate_ipv6("2345:0425:2CA1:0000:0000:0567:5673:23b5")
# -> True
Validator.validate_ipv6("0425:2CA1:0000:0000:0567:5673:23b5")
# -> False

Authors

License 🔑

MIT - Copyright (c) 2022 Beksultan Artykbaev

Metadata

Release files for stringtools 3.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for stringtools 3.0.1
File Size Uploaded Provenance
stringtools-3.0.1.tar.gz 8.5 MB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for stringtools 3.0.1
File Interpreter ABI Platform
stringtools-3.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 17.0 MB

Release files / stringtools-3.0.1.tar.gz

Download URL stringtools-3.0.1.tar.gz
Size 8.5 MB
Tags Source
SHA-256 checksum
How to use checksums
9e6b63d3b3138c8cdfdbf0cf42a8b291f6f1a55d21ee039ccbd37d8b1fde50ff
BLAKE2b-256 checksum
How to use checksums
9eaea1f2df4b156b5bf34a22cf4b8bea90d859c5766b0ee6212c67a7fc73d95b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.15

Release files / stringtools-3.0.1-py3-none-any.whl

Download URL stringtools-3.0.1-py3-none-any.whl
Size 8.5 MB
Tags Python 3
SHA-256 checksum
How to use checksums
b65ee1222a551b0e779846529ef549bc35ca0bd4f4ebe29bcb966453266834ca
BLAKE2b-256 checksum
How to use checksums
2f56b100f2e7dd75a8c2f673a84c25c24ec2b3c7d86e771322a9e52861091082
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.15

Security for stringtools 3.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page