This release is a pre-release and may not be stable for production use.
liwca (LOO-kə), or Linguistic Inquiry Word Count Assistant, provides helpers for working with LIWC dictionaries and related text analyses in Python.
- Read, write, and merge dictionary files (
.dic,dicx) - Generate category and word frequencies
- Generate Distributed Dictionary Representation (DDR) scores
- Run the LIWC app from Python (requires
LIWC-22-cliaccess) - Download publicly accessible dictionaries, corpora, and other relevant datasets
See the online docs for more detail.
Installation
pip install --upgrade liwca
Usage
Input/output
Read and write local LIWC-style dictionary files as Pandas DataFrames with schema validation.
import liwca
# Read a local dic file
dx = liwca.read_dic("my.dic")
# Read a local dicx file
dx = liwca.read_dicx("my.dicx")
# Read a local weighted dicx file
dx = liwca.read_dicx_weighted("myweighted.dicx")
# Create a dictionary from a collection of words
dx = liwca.create_dx(
{
"fruit": ["apple*", "pear*"],
"vegetables": ["broccoli", "carrot*"],
}
)
# Write the dictionary to a new file of any type
liwca.write_dic(dx, "fruit.dic")
liwca.write_dicx(dx, "fruit.dicx")
liwca.write_dicx_weighted(dx, "fruitweighted.dicx")
Word counting
Get category-level frequency scores for each text in a corpus. This will provide similar results to liwca.Liwc22().wc(), but does not require the LIWC-22 app and has the optional benefit of returning word-level frequencies. This is possible because the CountVectorizer from scikit-learn is used to calculate frequencies instead of the LIWC-22 app.
import liwca
# Generate some sample data
food_texts = [
"My friends likes apples.",
"She prefers pears over carrots.",
"What I would do for a carrot right now!",
"I am excited for pancakes tomorrow morning.",
]
food_categories = {
"fruit": ["apple*", "pear*"],
"vegetables": ["broccoli", "carrot*"],
}
food_dx = liwca.create_dx(food_categories)
# Return results at the category and word levels
cat_scores, word_scores = liwca.count(food_texts, food_dx, return_words=True)
cat_scores
# Category WC fruit vegetables
# text_id
# 0 4 0.25 0.000000
# 1 5 0.20 0.200000
# 2 9 0.00 0.111111
# 3 7 0.00 0.000000
word_scores
# WC apples broccoli carrot carrots pears
# text_id
# 0 4 0.25 0.0 0.0 0.0 0.0
# 1 5 0.0 0.0 0.0 0.2 0.2
# 2 9 0.0 0.0 0.111111 0.0 0.0
# 3 7 0.0 0.0 0.0 0.0 0.0
LIWC-22 CLI wrapper
The primary benefits of the LIWC-22 CLI wrapper are:
- Opens and closes the LIWC-22 app automatically and keeps it in the background (GUI does not open)
- Pure Python implementation (e.g., cleaner scripts if pre/post operations are also in Python)
- Cleaner argument names (e.g., text_columns instead of id_columns)
- Cleaner argument types (e.g., bool True/False instead of yes/no strings)
- Improved formatting for results output file (e.g., keep original row ID column name instead of renaming to id)
import liwca
import pandas as pd
texts = pd.Series(food_texts)
outpath = "./test_results.csv"
with liwca.Liwc22() as liwc:
liwc.wc(texts, outpath, include_categories=["Tone", "ppron", "food", "death"])
cat_scores = pd.read_csv(outpath, index_col=0)
# Tone ppron food death
# Row ID
# 1 99.00 25.00 0.00 0
# 2 20.23 20.00 0.00 0
# 3 20.23 11.11 0.00 0
# 4 99.00 14.29 14.29 0
cat_scores.dtypes
# Tone float64
# ppron float64
# food float64
# death int64
# dtype: object
Fetch public datasets
The liwca.datasets subpackage has multiple modules for fetching publicly available resources. Fetching includes downloading the file (if not already downloaded), caching it in local storage (to prevent re-downloading next time), preprocessing the file to fit standard formats, and also caching the preprocessed version.
from liwca.datasets import corpora, dictionaries
texts = corpora.fetch_hippocorpus()
texts.columns
# Index(['AssignmentId', 'WorkTimeInSeconds', 'WorkerId', 'annotatorAge',
# 'annotatorGender', 'annotatorRace', 'distracted', 'draining',
# 'frequency', 'importance', 'logTimeSinceEvent', 'mainEvent', 'memType',
# 'mostSurprising', 'openness', 'recAgnPairId', 'recImgPairId',
# 'similarity', 'similarityReason', 'story', 'stressful', 'summary',
# 'timeSinceEvent'],
# dtype='str')
texts["story"].head()
# 0 Concerts are my most favorite thing, and my bo...
# 1 The day started perfectly, with a great drive ...
# 2 It seems just like yesterday but today makes f...
# 3 Five months ago, my niece and nephew were born...
# 4 About a month ago I went to burning man. I was...
# Name: story, dtype: str
dx = dictionaries.fetch_threat()
# Category threat
# DicTerm
# accidents 1
# accusations 1
# advised 1
# afraid 1
# aftermath 1
# ... ...
# woes 1
# worries 1
# worry 1
# worse 1
# worst 1
Similar projects
Metadata
Release files for liwca 0.1.0a4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| liwca-0.1.0a4.tar.gz | 88.7 kB | With provenance | Details for liwca-0.1.0a4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| liwca-0.1.0a4-py3-none-any.whl | Python 3 | none | any | Details for liwca-0.1.0a4-py3-none-any.whl |
Total release size: 150.5 kB
Release files / liwca-0.1.0a4.tar.gz
| Download URL | liwca-0.1.0a4.tar.gz |
|---|---|
| Size | 88.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
eed37e5216ca692d042d53ab1d08f21b6fd0f683b0c5ee9c7dc0dbbc8edc3a46
|
|
BLAKE2b-256 checksum How to use checksums |
9b4452fa6bf85575f205a3099f7f3b3e8df38b4abd80c75450a4c9c23c6cd625
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 25, 2026.
Transparency logRelease files / liwca-0.1.0a4-py3-none-any.whl
| Download URL | liwca-0.1.0a4-py3-none-any.whl |
|---|---|
| Size | 61.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
51e49716c26ab29ef7188ae5ae7fc2d31ae9de6b8e117f404fdf921ab7a022d8
|
|
BLAKE2b-256 checksum How to use checksums |
fbb7c2a3d9f1a8aeef5e9ec8194c81402b50204cb4f0f8affa8b8a0c10c23b85
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 25, 2026.
Transparency logSecurity for liwca 0.1.0a4
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for liwca-0.1.0a4.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 25, 2026.
Transparency logA 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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.