| Crates.io | omniparse |
| lib.rs | omniparse |
| version | 0.2.1 |
| created_at | 2025-11-19 04:53:42.213854+00 |
| updated_at | 2025-11-20 14:08:24.918591+00 |
| description | A Rust toolkit for detecting and extracting metadata, text, and content from various file formats |
| homepage | |
| repository | https://github.com/sirhco/omniparse |
| max_upload_size | |
| id | 1939423 |
| size | 1,572,016 |
A Rust toolkit for detecting and extracting metadata, text, and content from hundreds of different file formats. Omniparse provides both a command-line interface and a library API, serving as a Rust equivalent to Apache Tika.
Add Omniparse to your Cargo.toml:
[dependencies]
omniparse = "0.1"
For async support:
[dependencies]
omniparse = { version = "0.1", features = ["async"] }
For parallel processing:
[dependencies]
omniparse = { version = "0.1", features = ["parallel"] }
Install using Cargo:
cargo install omniparse
Or build from source:
git clone https://github.com/omniparse/omniparse
cd omniparse
cargo build --release
The binary will be available at target/release/omniparse.
use omniparse::extract_from_path;
fn main() -> Result<(), omniparse::Error> {
// Extract from a file
let result = extract_from_path("document.pdf")?;
println!("MIME type: {}", result.mime_type);
println!("Confidence: {:.2}", result.detection_confidence);
// Access content
if let omniparse::Content::Text(text) = result.content {
println!("Text content: {}", text);
}
// Access metadata
if let Some(title) = result.metadata.title() {
println!("Title: {}", title);
}
if let Some(author) = result.metadata.author() {
println!("Author: {}", author);
}
Ok(())
}
use omniparse::extract_from_bytes;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let data = std::fs::read("file.json")?;
// With automatic type detection
let result = extract_from_bytes(&data, None)?;
// Or with a MIME type hint
let result = extract_from_bytes(&data, Some("application/json"))?;
println!("Detected: {}", result.mime_type);
Ok(())
}
use omniparse::extract_from_path_async;
#[tokio::main]
async fn main() -> Result<(), omniparse::Error> {
let result = extract_from_path_async("document.pdf").await?;
println!("Extracted: {}", result.mime_type);
Ok(())
}
use omniparse::{supported_mime_types, is_mime_supported};
fn main() {
// Get all supported MIME types
let types = supported_mime_types();
println!("Supported formats: {}", types.len());
// Check if a specific format is supported
if is_mime_supported("application/pdf") {
println!("PDF is supported!");
}
}
use omniparse::core::Extractor;
use omniparse::utils::parallel::process_files_parallel;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let extractor = Extractor::new();
let files = vec!["file1.pdf", "file2.docx", "file3.txt"];
// Process files in parallel
let results = process_files_parallel(&extractor, &files);
for file_result in results {
match file_result.result {
Ok(extraction) => {
println!("{}: {} (confidence: {:.2})",
file_result.path,
extraction.mime_type,
extraction.detection_confidence
);
}
Err(e) => {
eprintln!("{}: Error - {}", file_result.path, e);
}
}
}
Ok(())
}
# Extract from a single file
omniparse document.pdf
# Extract from multiple files
omniparse file1.txt file2.docx file3.pdf
# JSON output
omniparse --format json document.pdf
# YAML output
omniparse --format yaml document.pdf
# Save to file
omniparse --output results.json --format json document.pdf
# Extract only metadata, no content
omniparse --metadata-only document.pdf
# Detect file type without extraction
omniparse --detect-only unknown_file.bin
# Process multiple files in parallel
omniparse --parallel *.pdf
# Enable verbose logging
omniparse --verbose file1.pdf file2.pdf file3.pdf
# Metadata only, JSON format, parallel processing
omniparse --metadata-only --format json --parallel --output metadata.json *.pdf
# Extract from HTML files (web pages)
omniparse webpage.html index.htm
omniparse --format json --metadata-only page.html
# Extract from CSS files (stylesheets)
omniparse styles.css theme.css
omniparse --format json stylesheet.css # Get rule and selector counts
# Extract from RTF files (rich text)
omniparse document.rtf letter.rtf
omniparse --metadata-only report.rtf
# Extract from spreadsheets (Excel and OpenDocument)
omniparse data.xlsx spreadsheet.xls budget.ods
omniparse --format json --output data.json financial.xlsx
omniparse --parallel *.xlsx *.xls *.ods # Process multiple spreadsheets
# Extract from presentations (PowerPoint and OpenDocument)
omniparse slides.pptx presentation.ppt deck.odp
omniparse --metadata-only quarterly-review.pptx # Get slide count and metadata
omniparse --format json --output slides.json presentation.pptx
# Extract from legacy Office files (DOC, XLS, PPT)
omniparse document.doc old-report.doc
omniparse spreadsheet.xls data-2010.xls
omniparse presentation.ppt slides-archive.ppt
# Mixed format batch processing
omniparse --parallel --format json --output results.json *.html *.css *.rtf *.xlsx *.pptx
Omniparse provides detailed error types for different failure scenarios:
use omniparse::{extract_from_path, Error};
match extract_from_path("file.xyz") {
Ok(result) => {
println!("Success: {}", result.mime_type);
}
Err(Error::UnsupportedFormat(mime)) => {
eprintln!("Format {} is not supported", mime);
}
Err(Error::Io(e)) => {
eprintln!("IO error: {}", e);
}
Err(Error::CorruptedFile(msg)) => {
eprintln!("File is corrupted: {}", msg);
}
Err(Error::PartialExtraction { message, partial_result }) => {
eprintln!("Warning: {}", message);
println!("Partial content available: {:?}", partial_result.content);
}
Err(e) => {
eprintln!("Error: {}", e);
}
}
Omniparse has recently added support for 9 additional document formats:
See SUPPORTED_FORMATS.md for detailed information about each format.
Omniparse is designed for performance:
Typical performance on standard hardware:
All performance targets met or exceeded. See FINAL_PERFORMANCE_SUMMARY.md for comprehensive benchmark results.
Omniparse follows a modular architecture:
┌─────────────────┐
│ CLI / API │
└────────┬────────┘
│
┌────────▼────────┐
│ Extractor │
└────┬───────┬────┘
│ │
┌────▼───┐ ┌▼──────────┐
│Detector│ │ Registry │
└────────┘ └─────┬──────┘
│
┌───────┴───────┐
│ Parsers │
├───────────────┤
│ Text │
│ Document │
│ Image │
│ Archive │
└───────────────┘
cargo doc --open for detailed API docsContributions are welcome! Areas for contribution:
Licensed under either of:
at your option.
Inspired by Apache Tika, the Java-based content analysis toolkit.