Skip to main content

TextBlob

Requirements

  • Python >= 2.7, but not Python 3 (yet)

Installation

Just run:

$ pip install textblob && python download_corpora.py

This installs textblob and downloads the necessary NLTK models.

Best to see that everything is working by running:

$ nosetests

Usage

Simple.

from text.blob import TextBlob

text = """Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
"""

zen = TextBlob(text) # Create a new TextBlob
# Get the part-of-speech tags
zen.pos_tags         # [('beautiful', 'JJ'), ('is', 'VBZ'), ('better', 'RBR'),
                     # ('than', 'IN'), ('ugly', 'RB'), ...]
# Get the noun_phrases
zen.noun_phrases     # ['beautiful', 'explicit', 'simple', 'complex', 'flat',
                     # 'sparse', 'readability', 'special cases',
                     # 'practicality beats purity', 'errors', 'unless',
                     # 'obvious way','dutch', '*right* now', 'bad idea',
                     # 'good idea', 'namespaces', 'great idea']

# Get word and noun phrase frequencies
zen.word_counts['better']    # 10
zen.word_counts['idea']      # 3
zen.np_counts['great idea']  # 1

# Get the start and end indices of sentences within a blob
# This is useful for text highlighting, for example
for sentence in blob.sentences:
    print(sentence)  # Beautiful is better than ugly
    print("---- Starts at index {}, Ends at index {}"\
                .format(sentence.start_index, sentence.end_index))  # 0, 30

# TextBlobs are like Python strings!
zen[0:19]            # TextBlob("Beautiful is better")
zen.upper()          # TextBlob("BEAUTIFUL IS BETTER THAN UGLY...")
zen.find("purity")   # 293

blob1 = TextBlob('apples')
blob2 = TextBlob('bananas')
blob1 < blob2            # True
blob1 + ' and ' + blob2  # TextBlob('apples and bananas')

# Get a serialized version of the blob (a list of dicts)
zen.serialized       # [{'end_index': 30,
                     # 'noun_phrases': ['beautiful'],
                     # 'raw_sentence': 'Beautiful is better than ugly.',
                     # 'start_index': 0,
                     # 'stripped_sentence': 'beautiful is better than ugly'},

Testing

Run $ nosetests to run all tests.

Metadata

Release files for textblob 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 textblob 0.1
File Size Uploaded
textblob-0.1.tar.gz 7.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for textblob 0.1
File Interpreter ABI Platform
textblob-0.1.macosx-10.7-x86_64.exe Details

Total release size: 79.8 kB

Release files / textblob-0.1.tar.gz

Download URL textblob-0.1.tar.gz
Size 7.4 kB
Tags Source
SHA-256 checksum
How to use checksums
648bc0a37c52e978e4626a8d5d34a85b09ca65e7e42f4ab725f95c50c0fda3b2
BLAKE2b-256 checksum
How to use checksums
84434edbf77d88f11e2dc5868210b989f8cc8c827f7aca3f8a4e884fd933bc61
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / textblob-0.1.macosx-10.7-x86_64.exe

Download URL textblob-0.1.macosx-10.7-x86_64.exe
Size 72.5 kB
Tags Source
SHA-256 checksum
How to use checksums
1ae887c396a459dba9d04c3f424f7030c1754678be3f7a6d96f00110cc41b6d6
BLAKE2b-256 checksum
How to use checksums
b44b1fe2b1a614408409e158396761442089be99552e76624c6dac10b3ef88af
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

0.20.1

2 release files

0.19.0

2 release files

0.18.0

2 release files

0.17.1

2 release files

0.17.0

2 release files

0.15.3

2 release files

0.15.2

2 release files

0.15.1

2 release files

0.14.0

2 release files

0.13.1

2 release files

0.13.0

2 release files

0.12.0

2 release files

0.11.1

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.8.4

2 release files

0.8.3

2 release files

0.8.2

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.3

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.9

2 release files

0.3.8

2 release files

0.3.7

3 release files

0.3.6

1 release file

0.3.5

1 release file

0.3.4

1 release file

0.3.3

1 release file

0.3.2

1 release file

0.3.1

1 release file

0.3.0

1 release file

0.2.6

1 release file

0.2.5

1 release file

0.2.4

1 release file

0.2.3

1 release file

0.2.1

1 release file

0.2.0

1 release file

0.1.36

1 release file

0.1.35

1 release file

0.1.34

1 release file

0.1.33

1 release file

0.1.32

1 release file

0.1.31

1 release file

0.1.3

1 release file

0.1.2

1 release file

This release

0.1 This release

2 release files

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