Skip to main content

gemini-parser

Seamless Document Processing with Google Gemini API

🌍 gemini-parser is your all-in-one Python library for document parsing using the Google Gemini API.

⚡ It enables developers to transcribe PDFs, extract structured data, and summarize large documents with ease.

🚀 Whether you're transcribing PDFs, extracting structured data, or summarizing large documents, gemini-parser delivers fast, reliable, and efficient results.


🔥 Why choose gemini-parser?

  • 🚀 AI-powered document parsing with Google Gemini API.
  • 📦 Handles large files effortlessly (up to 20GB).
  • Smart caching for faster processing and reduced costs.
  • 📑 Supports multiple formats: PDF, CSV, HTML, DOC, XML, TXT.
  • 🌐 Flexible inputs from local files, folders, or URLs.
  • 📊 Structured data extraction for easy analysis.
  • 📜 Handle Large output context unlike gemini output context of ~8000 tokens, gemini-parser doesn't have a limit.

📦 Installation

pip install gemini-parser

Usage

⚠️ The library works perfectly fine for PDFs now. For other files type I will be adding support soon.

Quickstart Example

from gemini_parser import DocumentProcessor
from pathlib import Path
import os
from dotenv import load_dotenv

load_dotenv()

# Initialize processor with API key
processor = DocumentProcessor(api_key=os.getenv("GEMINI_API_KEY"))

# Process a single PDF file
result = processor.process_file(Path("path/to/document.pdf"))
print(result)

# Process from a URL
url_result = processor.process_from_url("https://example.com/document.pdf")
print(url_result)

# Process all files in a folder
processor.process_folder(Path("path/to/folder"))

# List all caches
caches = processor.list_caches()
print(caches)

# Delete a cache
processor.delete_cache("cachedContentID")

Configuration

You can customize key parameters when initializing the DocumentProcessor:

  • api_key: Your Gemini API key.
  • model_name: The Gemini model (e.g., gemini-1.5-flash-002).
  • prompt: The default processing prompt.
  • log_level: Logging level (INFO, DEBUG, etc.).

API Reference

DocumentProcessor

  • process_file(file_path, use_cache=False, cache_ttl=None): Processes a local file.
  • process_from_url(url, use_cache=False, cache_ttl=None): Processes a document from a URL.
  • process_multiple_files(file_paths, use_cache=False, cache_ttl=None): Processes multiple files.
  • process_folder(folder_path, output_dir=None, out_ext="md", use_cache=False, cache_ttl=None): Processes all files in a folder.
  • list_caches(): Lists all available caches.
  • delete_cache(cache_name): Deletes a cache by name.

FileManager

  • upload_file(file_or_path, mime_type): Uploads files to Gemini.
  • list_files(): Lists all uploaded files.
  • get_file(file_name): Gets metadata of a file.
  • delete_file(file_name): Deletes an uploaded file.

CachingManager

  • create_cache(model_name, contents, system_instruction): Creates a new cache.
  • generate_with_cache(model_name, cached_content_name, prompt): Generates content using a cache.
  • list_caches(): Lists all cached content.
  • update_cache_ttl(cache_name, hours): Updates the cache TTL.
  • delete_cache(cache_name): Deletes a cache.

Testing

Your library includes pytest-based tests in the tests/ folder. Run them with:

pytest tests/

Requirements

  • Python 3.8+
  • tqdm
  • PyPDF2
  • google-genai
  • python-dotenv
  • httpx

Project Structure

gemini-parser/
│
├── gemini_parser/
│   ├── document_processor.py
│   ├── file_manager.py
│   ├── caching.py
│   ├── utils.py
│
├── tests/
│   ├── test_gemini_parser.py
│
├── setup.py
├── pyproject.toml
├── README.md
└── LICENSE

License

This project is licensed under the MIT License.


Contributing

Contributions are welcome! Please fork this repository, create a new branch, and submit a pull request.


Author

Developed by Thimira Nirmal
📧 timnirmal@gmail.com
🌐 GitHub | Website

Release files for gemini-parser 0.1.0.post2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gemini-parser 0.1.0.post2
File Size Uploaded
gemini-parser-0.1.0.post2.tar.gz 12.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gemini-parser 0.1.0.post2
File Interpreter ABI Platform
gemini_parser-0.1.0.post2-py3-none-any.whl Python 3 none any Details

Total release size: 22.7 kB

Release files / gemini-parser-0.1.0.post2.tar.gz

Download URL gemini-parser-0.1.0.post2.tar.gz
Size 12.3 kB
Tags Source
SHA-256 checksum
How to use checksums
82145a4e9b40ebe55f2e7c7148c437c36fa5b6c6d4ed625a2bd55cb2323302dd
BLAKE2b-256 checksum
How to use checksums
cb0ef9824bfa9e40c64e108a2e6e46063da34b80b26b40b05525a904251a2510
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.0

Release files / gemini_parser-0.1.0.post2-py3-none-any.whl

Download URL gemini_parser-0.1.0.post2-py3-none-any.whl
Size 10.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
507bb0a70bb43aaa34cfcd900ae5c072c3b351a74d5aa2bea11d964606880690
BLAKE2b-256 checksum
How to use checksums
c31c2493f3bd0531adb0be62ef0209b2f450fbaf5909bdd31af98b5bc1ae41a6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.0

Release history Release notifications | RSS feed

This release

0.1.0.post2 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page