{"library":"python-documentcloud","title":"python-documentcloud","description":"python-documentcloud is a simple Python wrapper for the DocumentCloud API (current version 4.5.0). It provides convenient methods to retrieve and edit documents and projects, both public and private, directly from documentcloud.org. Users can upload PDFs into their DocumentCloud account, organize them into projects, and download extracted text and images. The library is actively maintained by MuckRock and sees a monthly to quarterly release cadence for updates and new features.","language":"python","status":"active","last_verified":"Thu Apr 16","install":{"commands":["pip install python-documentcloud"],"cli":null},"imports":["from documentcloud import DocumentCloud","from documentcloud.exceptions import APIError"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import os\nfrom documentcloud import DocumentCloud\n\n# Authenticate using environment variables for security\nUSERNAME = os.environ.get('DC_USERNAME', '')\nPASSWORD = os.environ.get('DC_PASSWORD', '')\n\ntry:\n    # Initialize the client. For private documents/actions, provide credentials.\n    # For public documents, no credentials are required.\n    client = DocumentCloud(USERNAME, PASSWORD)\n\n    # Search for documents\n    query = 'MuckRock'\n    print(f\"Searching for documents with query: '{query}'\")\n    documents = client.documents.search(query)\n\n    if documents:\n        print(f\"Found {len(documents)} documents:\")\n        for doc in documents:\n            print(f\"  - ID: {doc.id}, Title: {doc.title}, Status: {doc.status}\")\n\n        # Access a specific document by ID (replace with a real ID)\n        first_doc_id = documents[0].id\n        doc = client.documents.get(first_doc_id)\n        print(f\"\\nRetrieved document ID {doc.id}: '{doc.title}'\")\n        print(f\"  Source: {doc.source}\")\n    else:\n        print(\"No documents found for the given query.\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n    print(\"Ensure DC_USERNAME and DC_PASSWORD environment variables are set if accessing private data.\")\n","lang":"python","description":"This quickstart demonstrates how to initialize the DocumentCloud client and perform a basic search for documents. Authentication is handled via environment variables (`DC_USERNAME`, `DC_PASSWORD`) for secure credential management. It then iterates through the search results and fetches a specific document by ID.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}