Last modified: Apr 03, 2025 By Alexander Williams
How to Install Scrubadub in Python
Scrubadub is a Python library for cleaning personally identifiable information (PII) from text. It helps protect privacy by removing sensitive data. This guide will walk you through installing and using it.
Table Of Contents
Prerequisites
Before installing Scrubadub, ensure you have Python 3.6 or later. You can check your Python version using python --version
in your terminal.
python --version
If you don't have Python installed, download it from the official website first.
Install Scrubadub Using pip
The easiest way to install Scrubadub is via pip, Python's package manager. Open your terminal or command prompt and run:
pip install scrubadub
This will download and install Scrubadub and its dependencies. Wait for the installation to complete.
Verify the Installation
After installation, verify it works by importing it in Python. Open a Python shell and try:
import scrubadub
print(scrubadub.__version__)
If you see a version number, the installation was successful. If you get an error, check our guide on How To Solve ModuleNotFoundError.
Basic Usage Example
Here's a simple example of how to use Scrubadub to clean text:
from scrubadub import Scrubber
text = "Contact me at john.doe@example.com or call 555-123-4567."
scrubber = Scrubber()
clean_text = scrubber.scrub(text)
print(clean_text)
This will output:
Contact me at {{EMAIL}} or call {{PHONE}}.
Scrubadub automatically detected and replaced the email and phone number.
Customizing Scrubadub
You can customize what Scrubadub detects. For example, to add a custom detector:
from scrubadub.detectors import RegexDetector
from scrubadub.filth import Filth
class ZipCodeDetector(RegexDetector):
filth_type = 'zip'
regex = r'\b\d{5}(?:[-\s]\d{4})?\b'
scrubber = Scrubber()
scrubber.add_detector(ZipCodeDetector())
text = "My zip code is 90210."
print(scrubber.scrub(text))
This will output:
My zip code is {{ZIP}}.
Common Installation Issues
If you encounter errors during installation, try these solutions:
1. Permission errors: Use pip install --user scrubadub
to install for your user only.
2. Outdated pip: Update pip first with python -m pip install --upgrade pip
.
3. Virtual environments: Consider using a virtual environment to avoid conflicts.
Conclusion
Installing Scrubadub in Python is straightforward with pip. This powerful library helps protect privacy by cleaning sensitive information from text. Remember to verify the installation and explore its customization options.
For more advanced usage, check the official Scrubadub documentation. If you face any issues, our guide on ModuleNotFoundError might help.