Chemical data extraction tool for researchers and chemists
Project description
Molscraper
Chemical data extraction tool for researchers, students, and industry professionals.
๐งช What is Molscraper?
Molscraper is a comprehensive Python tool that extracts detailed chemical compound information from PubChem's REST API. Transform chemical compound names into structured datasets containing molecular properties, safety information, applications, and more.
โจ Key Features
- ๐ฏ Advanced CAS Number Extraction - Multiple extraction strategies with automatic fallbacks
- ๐ Comprehensive Data Extraction - 11 standardized data fields per compound
- ๐ Advanced Safety Data - MSDS information and hazard classifications
- โก High Performance - Smart rate limiting and efficient API usage
- ๐ Python Integration - Use as CLI tool or import as Python library
- ๐ Research Ready - Outputs to CSV for immediate analysis
- ๐ Smart Recognition - Functional group identification and applications
๐ Quick Installation
Install from PyPI (recommended):
pip install molscraper
๐ Quick Start
Installation
pip install molscraper
Command Line Interface
# Extract data for specific compounds
molscraper -c "Benzaldehyde" "Caffeine" "Aspirin"
# From text file (one compound per line)
molscraper -f examples/compounds.txt
# From CSV (auto-detects compound column)
molscraper -f examples/research_data.csv -o results.csv
# From Excel file
molscraper -f examples/compound_list.xlsx --verbose
# Custom settings
molscraper -f my_data.csv --delay 0.5 --verbose
File Input Support
# Text files - one compound per line
molscraper -f compounds.txt
# CSV files - auto-detects compound columns
molscraper -f research_data.csv
# Excel files (.xlsx)
molscraper -f lab_compounds.xlsx
# JSON files
molscraper -f compound_list.json
# CSV with different separators
molscraper -f messy_data.csv
Note: For best results, name your CSV column "compound" or "chemical", though other column names are automatically detected.
Python API
from molecule_scraper import process_compounds_to_csv, PubChemScraper
# Quick extraction to CSV
compounds = ["Benzaldehyde", "Caffeine", "Aspirin"]
df = process_compounds_to_csv(compounds, 'results.csv')
# Advanced usage with custom scraper
scraper = PubChemScraper(delay=0.3)
data = scraper.get_compound_data("Morphine")
print(f"CAS Number: {data.cas_number}")
print(f"Formula: {data.chemical_formula}")
๐ Data Fields Extracted
| Field | Description |
|---|---|
| Chemical Species | IUPAC name |
| Functional Group | Applications and uses |
| Chemical Name | Common name |
| Chemical Formula | Molecular formula |
| Structural Formula | SMILES notation |
| Extended SMILES | Canonical SMILES |
| CAS# | Chemical registry number |
| Properties | Physical properties |
| Applications | Commercial uses |
| MSDS | Safety data |
| Hazard Information | Safety classifications |
๐ฏ Perfect for Chemists
Computational Chemists:
- Integrates seamlessly with existing Python workflows
- Works in Jupyter notebooks
- Compatible with pandas, numpy, matplotlib
- Easy to include in
requirements.txt
Academic Researchers:
- Reproducible research workflows
- Batch processing capabilities
- Publication-ready data formats
Industry Professionals:
- High-throughput compound analysis
- Automated safety data collection
- Integration with existing systems
๐ Input Formats
๐ Text Files (.txt)
Benzaldehyde
Caffeine
Aspirin
๐ CSV Files (.csv) - Auto-detects compound columns!
compound,category,priority
Aspirin,NSAID,High
Caffeine,Stimulant,Medium
Ibuprofen,NSAID,High
Supported column names: compound, chemical, molecule, name, substance, and others.
Supported separators: Commas, semicolons, tabs.
๐ Excel Files (.xlsx)
Just save your spreadsheet as Excel format - same auto-detection as CSV!
๐ JSON Files (.json)
{
"compounds": ["Benzaldehyde", "Caffeine", "Aspirin"],
"description": "Test compounds for analysis"
}
๐ง Data Format Support
The parser handles:
- Different separators (
,;\t) - Various encodings (UTF-8, Latin1, etc.)
- Headers and metadata
- Quoted fields
- Empty rows
Note: Most standard data files work without reformatting.
๐ฏ Try Our Examples!
We've included ready-to-use example files:
# ๐งช Basic pharmaceutical compounds
molscraper -f examples/sample_compounds.txt
# ๐ฌ Research lignans and flavonoids
molscraper -f examples/research_data.csv --verbose
# ๐ Drug discovery compounds
molscraper -f examples/drug_discovery.csv
# ๐ฟ Natural products from traditional medicine
molscraper -f examples/natural_products.csv
# ๐ Excel file with therapeutic classifications
molscraper -f examples/compound_list.xlsx
# ๐ JSON format research compounds
molscraper -f examples/research_compounds.json
๐ New to molscraper? Check out our complete tutorial!
๐ ๏ธ Advanced Usage
CLI Options
molscraper --help
Options:
-c, --compounds TEXT Compound names (space-separated)
-f, --file PATH Input file (.txt or .json)
-o, --output PATH Output CSV file
--delay FLOAT Delay between requests (default: 0.2)
--verbose Enable detailed logging
--help Show this message and exit
Error Handling
The tool includes comprehensive error handling:
- Network timeouts and retries
- Invalid compound name detection
- API rate limit management
- Graceful degradation for partial data
๐ฌ Why Choose Molscraper?
vs. Manual PubChem Searches
- Automated batch processing vs manual lookup
- Consistent formatting across all compounds
- Batch processing capabilities
- Automated CAS number extraction
vs. Other Chemical APIs
- No API keys required - uses free PubChem REST API
- Advanced data extraction - gets safety and application data
- Robust CAS extraction - multiple strategies with automatic fallbacks
- Ready-to-use - no complex setup
vs. Basic Scripts
- Robust error handling - network timeouts and retries
- Rate limiting - respects API limits
- Comprehensive data - extracts 11+ data fields
- Structured output - standardized CSV format
๐ Examples
See the examples/ directory for:
compounds.txt- Basic compound listresearch_compounds.json- Research-focused compoundssample_output.csv- Example results
๐ค Contributing
For product feedback, feature requests, or questions, please reach out to: x@rhizome-research.com
๐ License
MIT License - see LICENSE file for details.
๐ Support
- Documentation: This README and inline code docs
- Contact: Send questions or feedback to x@rhizome-research.com
- Examples: Check the
examples/directory
Quick Start:
pip install molscraper
molscraper -c "Caffeine" -o test.csv
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file molscraper_tool-1.0.0.tar.gz.
File metadata
- Download URL: molscraper_tool-1.0.0.tar.gz
- Upload date:
- Size: 296.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e0aefea79d3c60413440efc2b0eca516445f80d16cef6850556640d032d23d95
|
|
| MD5 |
01e2344e8d5f0190e36ab597497b6fd3
|
|
| BLAKE2b-256 |
1be6d9bc073da17fa17c6660ab9641f7bb7d9163ccfc1c5d123e16e6dcf86d29
|
File details
Details for the file molscraper_tool-1.0.0-py3-none-any.whl.
File metadata
- Download URL: molscraper_tool-1.0.0-py3-none-any.whl
- Upload date:
- Size: 281.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4ffa57415ad67727ae401fe4f6dea7f8ba12fd1ced6226a2e3fb8e6d72835d30
|
|
| MD5 |
485f7bbdc918bb6e8544a83534f11425
|
|
| BLAKE2b-256 |
35c0cb9ebcd067ea7b11a28a5390f8cc1ce6a2403b626c3988d702c4549c88bd
|