Python library for implementing string-like classes and lazy strings
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.



Build Status Coverage Status PyPi package PyPi downloads

A Python library for implementing string-like classes and lazy strings.


stringlike is available from PyPI.

To install:

$ pip install stringlike

Or from the source:

$ python install


To implement your own StringLike class, inherit from StringLike and implement the __str__ magic function, like this:

from stringlike import StringLike

class StringyThingy(StringLike):
    def __str__(self):
        return self.text_type("A string representation of my class.")
Instances of StringLike class have a text_type property. By default it holds a propper string type for current version of Python: str for Python 3 and unicode for Python 2.

You can redefine text_type property for your needs.

It's strongly recommended to use it anyway just to make your code compatible with different versions of Python.

Use the provided lazy string implementations like this:

from stringlike.lazy import LazyString, CachedLazyString

print "This was lazily {str}".format(str=LazyString(lambda: "generated"))
print "This is {str}".format(str=CachedLazyString(lambda: "cached"))

A more detailed example can be found here.

Unit Tests

To run the unit tests, do this:

$ python tests/

To see the latest test results, check out stringlike's Travis CI page.


Special thanks to Eric Shull for much Python help!


This package is released under the MIT License. (See LICENSE.txt.)