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

Uploaded Python 3

File details

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

File metadata

  • Download URL: docorator-0.1.2.tar.gz
  • Upload date:
  • Size: 6.8 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.2.tar.gz
Algorithm Hash digest
SHA256 45eddacc7816b4b3bcfad2ac1ed689ca637b81f548c29145ae6efc0900f06252
MD5 13e541675906dc87c7298ddb5118c7e8
BLAKE2b-256 443b9c375b9331bfbab94b44ad052e1ff8287bc7f9c52d7df2042636b959144f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: docorator-0.1.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 28c0c86889b74a5836ce7ea978a1fae915b5107461926cdc092d824b75d81de1
MD5 6ca8d0fe2e28ac550ff17c96890ef991
BLAKE2b-256 876c7554a5e2d776b3d290222d763f39f3669f668694c9e196cef40e84e340ee

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