Skip to main content

Google Docs management library with Markdown support and persistent caching

Project description

Docorator

Docorator is a Python library for seamless Google Docs integration with persistent caching capabilities. It enables programmatic creation, editing, and management of Google Docs with Markdown support.

Features

  • Create and manage Google Docs through an intuitive Python interface
  • Convert between Google Docs and Markdown formats
  • Automatic document sharing and permission management
  • Threaded operations for non-blocking performance
  • Persistent caching via Cacherator
  • Detailed operation logging with Logorator
  • Support for converting between Markdown, HTML, and DOCX formats

Installation

pip install docorator

Requirements

  • Python 3.7+
  • Google API service account credentials

Quick Start

from docorator import Docorator

# Initialize with your service account key file
doco = Docorator(
    keyfile_path="service-account-key.json",
    email="your-email@example.com",  # Optional email to share the document with
    document_name="My Document"
)

# Wait for the document to load (creates a new document if it doesn't exist)
doco.wait_for_load()

# Get document content as Markdown
markdown_content = doco.as_markdown()
print(markdown_content)

# Update the document with new Markdown content
doco.save("# This is a headline\n\n## Section\n\nHello world!")

# Access the document URL
print(f"Document URL: {doco.url}")

Detailed Usage

Document Management

# Create or load a document
doco = Docorator(keyfile_path="key.json", email="user@example.com", document_name="My Document")

# Check if document exists (URL is None if document doesn't exist yet)
url = doco.url

# Force reload of document content
doco.load()

# Wait for background loading to complete
doc = doco.wait_for_load()  # Returns a python-docx Document object

# Get Markdown representation
md_content = doco.as_markdown()

# Save Markdown content
doco.save("# New Markdown Content")

# Save a python-docx Document object
from docx import Document
doc = Document()
doc.add_heading("New Document", 0)
doco.save(doc)

# Wait for background save to complete
save_success = doco.wait_for_save()

Asynchronous Operations

Docorator performs document operations in background threads to prevent blocking:

  • load() initiates document loading in a background thread
  • wait_for_load() blocks until loading completes
  • save() initiates document saving in a background thread
  • wait_for_save() blocks until saving completes

This threading model allows your application to remain responsive while document operations proceed in the background.

Caching System

Docorator leverages Cacherator for efficient document caching:

  • Document IDs, metadata, and state are cached to minimize API calls
  • Cache is stored in the data/docorator directory by default
  • To clear the cache for a document:
    doco = Docorator(
        keyfile_path="key.json", 
        email="user@example.com",
        document_name="My Document", 
        clear_cache=True
    )
    

Authentication

Docorator requires a Google service account with access to Google Docs and Drive APIs:

  1. Create a project in the Google Cloud Console
  2. Enable the Google Docs API and Google Drive API
  3. Create a service account and download the JSON key file
  4. Use the path to this key file in the keyfile_path parameter

For more details on setting up Google service accounts, see the Google Cloud documentation.

License

MIT

Dependencies

  • google-auth
  • google-api-python-client
  • python-docx
  • typing-extensions
  • google
  • logorator
  • cacherator
  • mammoth
  • html2docx
  • Markdown

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

docorator-0.1.1.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

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

docorator-0.1.1-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file docorator-0.1.1.tar.gz.

File metadata

  • Download URL: docorator-0.1.1.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for docorator-0.1.1.tar.gz
Algorithm Hash digest
SHA256 25020ac06aefe48f288f38b9e482a64a072c3fb2ca3908442633cf649be0378e
MD5 9144673563d8760c2813c8226098f009
BLAKE2b-256 7cfad9856a2113475099d871530758a37b10c7d4f225cf3e0996b5daf81800fd

See more details on using hashes here.

File details

Details for the file docorator-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: docorator-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for docorator-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 07cce4befbb6194079894d3e439377cb94451a31ccf45a9d9a7ade0cd4f739f5
MD5 6ab232dc405d9793d9d2c697b4b9c484
BLAKE2b-256 a12d9346b82a373c452907876d54d2476faf10524406d3705cce1ce62289674a

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