Skip to main content

A Python library for processing documents with the Gemini API

Project description

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

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

gemini-parser-0.1.0.post2.tar.gz (12.3 kB view details)

Uploaded Source

Built Distribution

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

gemini_parser-0.1.0.post2-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

Details for the file gemini-parser-0.1.0.post2.tar.gz.

File metadata

  • Download URL: gemini-parser-0.1.0.post2.tar.gz
  • Upload date:
  • Size: 12.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.0

File hashes

Hashes for gemini-parser-0.1.0.post2.tar.gz
Algorithm Hash digest
SHA256 82145a4e9b40ebe55f2e7c7148c437c36fa5b6c6d4ed625a2bd55cb2323302dd
MD5 4a115cc1c642fbe184832f76a940b86f
BLAKE2b-256 cb0ef9824bfa9e40c64e108a2e6e46063da34b80b26b40b05525a904251a2510

See more details on using hashes here.

File details

Details for the file gemini_parser-0.1.0.post2-py3-none-any.whl.

File metadata

File hashes

Hashes for gemini_parser-0.1.0.post2-py3-none-any.whl
Algorithm Hash digest
SHA256 507bb0a70bb43aaa34cfcd900ae5c072c3b351a74d5aa2bea11d964606880690
MD5 5251b58cda24684901e2e4b51b96a57d
BLAKE2b-256 c31c2493f3bd0531adb0be62ef0209b2f450fbaf5909bdd31af98b5bc1ae41a6

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