Observed since 20 Oct, 21:12 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
A Python package by Avokan for managing and querying African text corpora
A Python package for managing and querying African text corpora with flexible metadata-based filtering.
add() methodmatch and match_all optionspip install afrocorpus
Or from source:
git clone https://github.com/avokan-air/afrocorpus.git
cd afrocorpus
pip install -e .
After installation, download the corpus data files:
from afrocorpus import AfroCorpus
# Download corpus data (tries primary URL, falls back to backups if needed)
AfroCorpus.download_data()
The download function automatically:
To re-download and overwrite existing data:
AfroCorpus.download_data(force=True)
from afrocorpus import AfroCorpus
# First time: download the data
AfroCorpus.download_data()
# Load all documents
corpus = AfroCorpus()
print(f"Loaded {len(corpus)} documents")
# Load with filters
corpus = AfroCorpus({
"country": "bj",
"language": "fr",
"url": "wikipedia",
"date": ">2026-01-01"
})
# Get contents
texts = corpus.contents()
full_text = " ".join(texts)
# Add more documents with additional filters
corpus.add({"url": "nouvelletribune", "match_all": ["talon", "yayi"]})
If you have your own corpus files locally:
corpus = AfroCorpus(
filters={"language": "fr"},
data_dir="/path/to/your/data"
)
Text files should follow this format:
URL: https://example.com/article
Filename: article.txt
Language: fr
Last Updated: 2026-01-15T10:00:00.000000
Country: bj
================================================================================
Your article content goes here...
Lines 1-5 contain metadata, line 6 is an optional separator, and line 7+ contains the actual content.
| Filter | Description | Example |
|---|---|---|
country | Country code (defaults to "bj") | {"country": "bj"} |
language | Language code | {"language": "fr"} |
url | URL substring match | {"url": "wikipedia"} |
date | Date with operators (>, <, >=, <=, =) | {"date": ">2026-01-01"} |
match | At least one term must appear | {"match": ["term1", "term2"]} |
match_all | All terms must appear | {"match_all": ["term1", "term2"]} |
# Start with French documents from Benin
corpus = AfroCorpus({"country": "bj", "language": "fr"})
# Add English documents from Nigeria
corpus.add({"country": "ng", "language": "en"})
# Add any documents containing specific keywords
corpus.add({"match": ["economy", "politique"]})
corpus = AfroCorpus()
# Get total number of documents
print(len(corpus))
# Access first document
first_doc = corpus[0]
print(first_doc['url'])
print(first_doc['language'])
print(first_doc['content'][:100])
# Iterate through all documents
for doc in corpus.documents:
print(f"{doc['filename']}: {doc['language']}")
python -m pytest tests/
# or
python -m unittest discover tests
python -m build
python -m twine upload dist/*
Contributions are welcome! Please feel free to submit a Pull Request.
git checkout -b feature/AmazingFeature)git commit -m 'Add some AmazingFeature')git push origin feature/AmazingFeature)If download_data() fails:
force=True to re-download: AfroCorpus.download_data(force=True)If your corpus loads but has 0 documents:
AfroCorpus()MIT License - see LICENSE file for details.
Ola ABOUBAKAR (ola@avokan.com)
If you use AfroCorpus in your research, please cite:
@software{afrocorpus2026,
author = {Ola ABOUBAKAR},
title = {AfroCorpus: A Python Package for African Text Corpora},
year = {2026},
url = {https://github.com/avokan-air/afrocorpus}
}
Download counts and popularity will appear here as the collector receives them.
| Version | Published | Direct dependencies | Open version |
|---|---|---|---|
| 0.1.3 | 22 Jan 2026 | 0 |
This describes our collected data; it is not a security assessment.
Observed since 20 Oct, 21:12 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package:5aa514fcb433d120ae050620ef33980a7d416a123fe5b53c0760cec77a69c590