SyncString

class thread_factory.concurrency.sync_types.sync_string.SyncString(initial='')[source]

Bases: ISync

A thread-safe mutable wrapper around Python’s built-in immutable str.

πŸ” Core Purpose

Provides synchronized access to common string operations and behaviors using internal locking. Useful for concurrent environments where safe string manipulation is required.

πŸ”§ Features

  • Thread-safe string access and mutation.

  • Supports method forwarding for many built-in string methods.

  • Can be safely used in multithreaded programs.

βœ… Recommended Usage:

shared = SyncString(β€œinit”) shared.get() # Read thread-safely shared.set(β€œnew val”) # Write thread-safely shared.append(”…”) # Custom string manipulation methods

capitalize(*args, **kwargs)[source]

Return a copy of the string with its first character capitalized and the rest lowercased.

Thread-safe: Acquires internal lock during access.

casefold(*args, **kwargs)[source]

Return a casefolded copy of the string, more aggressive than lower() for caseless matching.

Thread-safe: Acquires internal lock during access.

center(*args, **kwargs)[source]

Return a centered string of given width with optional fill character (default is space).

Thread-safe: Acquires internal lock during access.

count(*args, **kwargs)[source]

Return the number of non-overlapping occurrences of a substring in the string.

Thread-safe: Acquires internal lock during access.

encode(*args, **kwargs)[source]

Encode the string using the codec registered for encoding. Default is β€˜utf-8’.

Thread-safe: Acquires internal lock during access.

endswith(*args, **kwargs)[source]

Return True if the string ends with the specified suffix; False otherwise.

Thread-safe: Acquires internal lock during access.

expandtabs(*args, **kwargs)[source]

Return a copy where all tab characters are replaced by spaces using tabsize (default 8).

Thread-safe: Acquires internal lock during access.

find(*args, **kwargs)[source]

Return the lowest index where the substring is found; -1 if not found.

Thread-safe: Acquires internal lock during access.

format(*args, **kwargs)[source]

Perform a string formatting operation using format specifiers.

Thread-safe: Acquires internal lock during access.

format_map(*args, **kwargs)[source]

Similar to format(), but uses a single mapping argument instead of positional and keyword.

Thread-safe: Acquires internal lock during access.

get() str[source]

Return the current string value.

Returns:

The current string value held by this object.

Return type:

str

This method acquires the internal lock before reading the value. It is the thread-safe equivalent of accessing the string directly.

index(*args, **kwargs)[source]

Return the lowest index where the substring is found.

Same as str.index(). Raises ValueError if the substring is not found.

This method is thread-safe.

isalnum(*args, **kwargs)[source]

Return True if the string is nonempty and all characters are alphanumeric.

Thread-safe variant of str.isalnum().

isalpha(*args, **kwargs)[source]

Return True if the string is nonempty and all characters are alphabetic.

Thread-safe variant of str.isalpha().

isascii(*args, **kwargs)[source]

Return True if all characters in the string are ASCII.

Thread-safe version of str.isascii().

isdecimal(*args, **kwargs)[source]

Return True if the string is nonempty and all characters are decimal characters.

Thread-safe wrapper around str.isdecimal().

isdigit(*args, **kwargs)[source]

Return True if all characters in the string are digits.

Thread-safe variant of str.isdigit().

isidentifier(*args, **kwargs)[source]

Return True if the string is a valid Python identifier.

Thread-safe version of str.isidentifier().

islower(*args, **kwargs)[source]

Return True if all cased characters are lowercase and the string has at least one cased character.

Thread-safe variant of str.islower().

isnumeric(*args, **kwargs)[source]

Return True if all characters in the string are numeric characters.

Thread-safe version of str.isnumeric().

isprintable(*args, **kwargs)[source]

Return True if all characters are printable or the string is empty.

Thread-safe wrapper around str.isprintable().

isspace(*args, **kwargs)[source]

Return True if all characters in the string are whitespace and the string is nonempty.

Thread-safe variant of str.isspace().

istitle(*args, **kwargs)[source]

Return True if the string is titlecased (i.e. upper-case letters followed by lower-case letters).

Thread-safe wrapper around str.istitle().

isupper(*args, **kwargs)[source]

Return True if all cased characters are uppercase and there is at least one cased character. Thread-safe.

join(*args, **kwargs)[source]

Concatenate any number of strings using the current string as a separator. Thread-safe.

Equivalent to: s.join(iterable)

ljust(*args, **kwargs)[source]

Return the string left-justified in a string of given width. Thread-safe.

Equivalent to: s.ljust(width[, fillchar])

lower(*args, **kwargs)[source]

Return a copy of the string converted to lowercase.

Thread-safe.

lstrip(*args, **kwargs)[source]

Return a copy of the string with leading whitespace removed.

Thread-safe.

maketrans(*args, **kwargs)[source]

Return a translation table usable for str.translate(). Thread-safe.

Can be used as: str.maketrans(x[, y[, z]])

partition(*args, **kwargs)[source]

Split the string at the first occurrence of sep, and return a 3-tuple. Thread-safe.

Equivalent to: s.partition(sep)

removeprefix(*args, **kwargs)[source]

Return a string with the specified prefix removed if present. Thread-safe.

Equivalent to: s.removeprefix(prefix)

removesuffix(*args, **kwargs)[source]

Return a string with the specified suffix removed if present. Thread-safe.

Equivalent to: s.removesuffix(suffix)

replace(*args, **kwargs)[source]

Return a copy with all occurrences of substring replaced by another. Thread-safe.

Equivalent to: s.replace(old, new[, count])

rfind(*args, **kwargs)[source]

Return the highest index where the substring is found, or -1 if not found. Thread-safe.

Equivalent to: s.rfind(sub[, start[, end]])

rindex(*args, **kwargs)[source]

Return the highest index where the substring is found, or raise ValueError. Thread-safe.

Equivalent to: s.rindex(sub[, start[, end]])

rjust(*args, **kwargs)[source]

Return the string right-justified in a string of given width. Thread-safe.

Equivalent to: s.rjust(width[, fillchar])

rpartition(*args, **kwargs)[source]

Return a 3-tuple where the string is split around the last occurrence of the separator.

If the separator is found, returns (head, sep, tail). If not, returns (β€˜β€™, β€˜β€™, original). Thread-safe.

rsplit(*args, **kwargs)[source]

Return a list of the words in the string, using sep as the delimiter string.

Performs a right split. If maxsplit is given, splits at most maxsplit times. Thread-safe.

rstrip(*args, **kwargs)[source]

Return a copy of the string with trailing whitespace removed.

If chars is given and not None, remove characters in chars instead. Thread-safe.

set(new_value: str)[source]

Set a new string value.

Parameters:

new_value (str) – The new value to assign to the internal string.

This method acquires the internal lock before updating the value. It allows atomic replacement of the internal string in concurrent settings.

split(*args, **kwargs)[source]

Return a list of the words in the string, using sep as the delimiter string.

If sep is not specified or is None, any whitespace string is a separator. Thread-safe.

splitlines(*args, **kwargs)[source]

Return a list of the lines in the string, breaking at line boundaries.

Line breaks are not included unless keepends is given and True. Thread-safe.

startswith(*args, **kwargs)[source]

Return True if the string starts with the specified prefix.

Can be limited by optional start and end arguments. Thread-safe.

strip(*args, **kwargs)[source]

Return a copy of the string with leading and trailing whitespace removed.

If chars is given and not None, remove characters in chars instead. Thread-safe.

swapcase(*args, **kwargs)[source]

Return a copy of the string with uppercase characters converted to lowercase and vice versa.

Thread-safe.

title(*args, **kwargs)[source]

Return a titlecased version of the string.

Words start with uppercase characters, all remaining characters are lowercase. Thread-safe.

translate(*args, **kwargs)[source]

Return a copy where each character has been mapped through the given translation table.

The table must be a mapping of Unicode ordinals to Unicode ordinals, strings, or None. Thread-safe.

upper(*args, **kwargs)[source]

Return a copy of the string converted to uppercase.

Thread-safe.

zfill(*args, **kwargs)[source]

Pad the string on the left with zeros to fill a field of the given width.

The original string is never truncated. Thread-safe.