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.3.tar.gz (6.9 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.3-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: docorator-0.1.3.tar.gz
  • Upload date:
  • Size: 6.9 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.3.tar.gz
Algorithm Hash digest
SHA256 7637363f3b42c0b4484ba44636e38c2c0fb1fb90f10807ed91fb89189b420029
MD5 44d16fc5743394aaba91df4e7ddb46ed
BLAKE2b-256 aef645ffdb59e7ed12b933f82afec14f77f23f4c49d8ad533f53a8366a554aff

See more details on using hashes here.

File details

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

File metadata

  • Download URL: docorator-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 7.0 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d57a8150a48ca5521bc9cf17bb5a6531972a85e936bd5c08da47d6ebc0984ba3
MD5 d0949c73d26eca2a7924fdcb43e94bb5
BLAKE2b-256 801bba80bff6c77c0972004009150a359d709123cbe4d0bd71f06d7c3a2bea41

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