Skip to main content

Chemical data extraction tool for researchers and chemists

Project description

Molscraper

PyPI version Python 3.8+ License: MIT

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 list
  • research_compounds.json - Research-focused compounds
  • sample_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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

molscraper_tool-1.0.0.tar.gz (296.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

molscraper_tool-1.0.0-py3-none-any.whl (281.3 kB view details)

Uploaded Python 3

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

Hashes for molscraper_tool-1.0.0.tar.gz
Algorithm Hash digest
SHA256 e0aefea79d3c60413440efc2b0eca516445f80d16cef6850556640d032d23d95
MD5 01e2344e8d5f0190e36ab597497b6fd3
BLAKE2b-256 1be6d9bc073da17fa17c6660ab9641f7bb7d9163ccfc1c5d123e16e6dcf86d29

See more details on using hashes here.

File details

Details for the file molscraper_tool-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for molscraper_tool-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4ffa57415ad67727ae401fe4f6dea7f8ba12fd1ced6226a2e3fb8e6d72835d30
MD5 485f7bbdc918bb6e8544a83534f11425
BLAKE2b-256 35c0cb9ebcd067ea7b11a28a5390f8cc1ce6a2403b626c3988d702c4549c88bd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page