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.0.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.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for docorator-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7d563cf830235168cd213eaf6d7b91fdac463bacfbc3c897d194f25915ecf9ea
MD5 764300da73b2c9c238d59625381869c4
BLAKE2b-256 5649115098e9d2c6522b19c63199ec257e850085d08ae3758ca777607ec57846

See more details on using hashes here.

File details

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

File metadata

  • Download URL: docorator-0.1.0-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.12.3

File hashes

Hashes for docorator-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 54cde6de97ab61f7cf2e5c526b5605148a29c730e1b541b52c63cddd8730e4c5
MD5 c4f5ab419ae8e6c9267fc244371d87b2
BLAKE2b-256 6a86c1dd3f37f1c4f8e0253e8ea5f9096c7e9d30a1cf13f6e01e9f831fed2bf8

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