A Python library for processing documents with the Gemini API
Project description
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+
tqdmPyPDF2google-genaipython-dotenvhttpx
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
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
82145a4e9b40ebe55f2e7c7148c437c36fa5b6c6d4ed625a2bd55cb2323302dd
|
|
| MD5 |
4a115cc1c642fbe184832f76a940b86f
|
|
| BLAKE2b-256 |
cb0ef9824bfa9e40c64e108a2e6e46063da34b80b26b40b05525a904251a2510
|
File details
Details for the file gemini_parser-0.1.0.post2-py3-none-any.whl.
File metadata
- Download URL: gemini_parser-0.1.0.post2-py3-none-any.whl
- Upload date:
- Size: 10.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
507bb0a70bb43aaa34cfcd900ae5c072c3b351a74d5aa2bea11d964606880690
|
|
| MD5 |
5251b58cda24684901e2e4b51b96a57d
|
|
| BLAKE2b-256 |
c31c2493f3bd0531adb0be62ef0209b2f450fbaf5909bdd31af98b5bc1ae41a6
|