Skip to main content

CleverText

Work in progress... copied from CleverDict


PyPI PyPI - Python Version Downloads PyPI - License PyPI - Status GitHub Repo stars

clevertext cartoon

>CONTENTS

  1. OVERVIEW
  2. INSTALLATION
  3. INPUT METHODS
  4. OUTPUT METHODS
  5. ATTRIBUTE NAMES AND ALIASES
  6. DEEPER DIVE INTO ATTRIBUTE NAMES
  7. SETTING AN ATTRIBUTE WITHOUT CREATING A DICTIONARY ITEM
  8. THE AUTO-SAVE FEATURE
  9. CREATING YOUR OWN AUTO-SAVE FUNCTION
  10. CONTRIBUTING
  11. CREDITS

1. OVERVIEW

CleverText is a convenience class that behaves almost exactly like regular Python string but also contain its own self-contained version history and record of actions. It is mainly intented for recording and comparing different states of text (string, HTML, JSON, code etc) as various transformations (replacements, deletions, validation, parsing) are applied to it. Built in CleverText methods (e.g. diff()) are readily available for ETL style processing, and can be added easily and consistently, allowing you to segregate common text manipulation function from your main control code for example.

2. INSTALLATION

Very lightweight install via pip. No dependencies.

python -m pip install clevertext --upgrade

Then from your Python shell just import the class...

>>> from clevertext import CleverText

3. INPUT METHODS

You can create a CleverText instance using keyword arguments:

>>> x = CleverText("This is the my first draft")

4. OUTPUT METHODS

5. ATTRIBUTES

6. BUILT-IN METHODS

7. ADDING YOUR OWN METHODS

8. ENABLING AUTO-SAVE

9. CREATING YOUR OWN AUTO-SAVE/AUTO-DELETE FUNCTION

As well as autosave/autodelete options baked in to CleverText, you can set pretty much any custom function to run automatically when a CleverText value is created, changed, or deleted, for example to update a database, save to a file, or synchronise with cloud storage etc. Less code for you, and less chance you'll forget to explicitly call that crucial update function...

This can be enabled at a class level, or by creating subclasses of CleverText with different options, or an object/instance level. We strongly recommend the object/instance approach wherever possible, but you have the choice.

Autosaving a particular object/instance:

You can either overwrite the .save() / .delete() methods when you create your object, or use .set_autosave() / .set_autodelete() after the event:

Autosaving at a class level:

Simple to do, but beware this could change all existing CleverText instances as well as all future ones:

>>> CleverText.save = your_save_function
>>> CleverText.delete = your_delete_function

Creating Subclasses:

If you create a subclass of CleverText remember to call super().__init__() before trying to set any further class or object attributes, otherwise you'll run into trouble:

class AutoStore(CleverText):
    def __init__(self, *args, **kwargs):
        self.setattr_direct('index', [])
        super().__init__(*args, **kwargs)

    def save(self, name, value):
        """ Keep a separate 'store' for data in .index """
        self.index.append((name, value))

class AutoConfirm(CleverText): pass
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

    def save(self, name, value):
        """ Print confirmation of the latest change """
        print(f"{name.title()}: {value.upper()}")

CONTRIBUTING METHODS AS PULL REQUESTS

10. CONTRIBUTING TO THE CORE DESIGN

We'd love to see Pull Requests (and relevant tests) from other contributors, particularly if you can help:

  • Evolve CleverText to make it play nicely with other classes and formats. For example: datetime.
  • Put the finishing touches on the docstrings to enable autocompletion in modern IDEs (this is neither the author's strong suit nor his passion!).
  • Improve the structure and coverage of test_clevertext.py.

For a list of all outstanding Feature Requests and (heaven forbid!) actual Issues please have a look here and maybe you can help out?

https://github.com/PFython/clevertext/issues?q=is%3Aopen+is%3Aissue

11. CREDITS

CleverText was conceived by Peter Fison and co-developed with the expert assistance of Ruud van der Ham from the friendly and excellent Pythonista Cafe forum (www.pythonistacafe.com).

It follows on from the success of CleverDict which is similar in concept and well worth checking out if you haven't already.

If you find clevertext helpful, please feel free to:

Buy Me A Coffee

Metadata

Release files for clevertext 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 clevertext 0.1
File Size Uploaded Provenance
clevertext-0.1.tar.gz 29.1 kB Without provenance Details

Release files / clevertext-0.1.tar.gz

Download URL clevertext-0.1.tar.gz
Size 29.1 kB
Tags Source
SHA-256 checksum
How to use checksums
7c8cca07b3d0fac8d9e9d62f7a57de929af7162af3ddea481defc992cf6bd823
BLAKE2b-256 checksum
How to use checksums
65b3f19b025328931ae94787bee5914c9bc75d4c587ebb4d59bb533cf77334a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.27.1 setuptools/60.5.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

Security for clevertext 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.

Release history Release notifications | RSS feed

This release

0.1 This release

1 release file No provenance

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