
Security News
Open Source CAI Framework Handles Pen Testing Tasks up to 3,600× Faster Than Humans
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Python library for defining strings with delayed evaluation.
|pypi_package| |python_versions| |license|
The package provides a LazyString
class. Its constructor accepts a callable (say, a function) which will be called when string's value is needed. The constructor also allows to specify positional and keyword arguments for that callable:
.. code-block:: python
def init(self, func: Callable[..., str], *args: Tuple, **kwargs: Mapping) -> None: ...
The value is re-evaluated on every access.
Available as a PyPI <https://pypi.python.org/pypi/lazy-string>
_ package:
.. code-block:: bash
pip install lazy-string
Using with a function having no parameters:
.. code-block:: python
from lazy_string import LazyString
def make_foo() -> str: return "foo"
s = LazyString(make_foo)
The value is evaluated on demand:
.. code-block:: python
s + " bar" 'foo bar'
str(s) 'foo'
Representation explicitly tells it's a LazyString
:
.. code-block:: python
s LazyString('foo')
It's safe to pass standard strings, as they will be returned as-is:
.. code-block:: python
LazyString("foo bar") 'foo bar'
Supports methods of standard strings:
.. code-block:: python
s.upper() 'FOO'
"f" in s True
dir(s) ['add', 'class', 'contains', 'delattr', 'dir', 'doc', 'eq', 'format', 'ge', 'getattribute', 'getitem', 'getnewargs', 'gt', 'hash', 'init', 'init_subclass', 'iter', 'le', 'len', 'lt', 'mod', 'mul', 'ne', 'new', 'reduce', 'reduce_ex', 'repr', 'rmod', 'rmul', 'setattr', 'sizeof', 'str', 'subclasshook', 'capitalize', 'casefold', 'center', 'count', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'format_map', 'index', 'isalnum', 'isalpha', 'isascii', 'isdecimal', 'isdigit', 'isidentifier', 'islower', 'isnumeric', 'isprintable', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'maketrans', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']
Supplying parameters for the callable:
.. code-block:: python
def make_foo(arg1, arg2): return f"foo {arg1} {arg2}"
s = LazyString(make_foo, 123, arg2=456)
.. code-block:: python
str(s) 'foo 123 456'
LazyString
is inherited from collections.UserString <https://docs.python.org/3/library/collections.html#collections.UserString>
_.
.. code-block:: python
LazyString.mro (<class 'lazy_string.LazyString'>, <class 'collections.UserString'>, <class 'collections.abc.Sequence'>, <class 'collections.abc.Reversible'>, <class 'collections.abc.Collection'>, <class 'collections.abc.Sized'>, <class 'collections.abc.Iterable'>, <class 'collections.abc.Container'>, <class 'object'>)
Pickling ^^^^^^^^
Supported out of the box:
.. code-block:: python
import pickle s == pickle.loads(pickle.dumps(s)) True
To JSON ^^^^^^^
Supported with any encoder able to encode collections.UserString
:
.. code-block:: python
import json import collections
class JSONEncoder(json.JSONEncoder):
def default(self, o):
if isinstance(o, collections.UserString):
return str(o)
return super().default(o)
.. code-block:: python
data = {'s': s} json.dumps(data, cls=JSONEncoder) '{"s": "foo"}'
.. |pypi_package| image:: https://img.shields.io/pypi/v/lazy-string :target: http://badge.fury.io/py/lazy-string/ :alt: Version of PyPI package
.. |python_versions| image:: https://img.shields.io/badge/Python-3.7+-brightgreen.svg :alt: Supported versions of Python
.. |license| image:: https://img.shields.io/badge/license-MIT-blue.svg :target: https://github.com/oblalex/lazy-string/blob/main/LICENSE :alt: MIT license
FAQs
Python library for defining strings with delayed evaluation
We found that lazy-string demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
Security News
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.