pyocclient Python Client for ownCloud

repository·master·Indexed 43 days ago

https://github.com/owncloud/pyocclient

A pure Python client library for the ownCloud API that abstracts HTTP and WebDAV calls. It provides high-level functions for file operations, sharing via the OCS Share API, user and group management via the OCS Provisioning API, and app management. Supports ownCloud versions 8.2, 9.0, 9.1, and newer.

Tokens
1.2K
Snippets
6
Records
7
Agent score
5%

What's inside pyocclient

  1. Overview of pyocclient capabilities

    master

    pyocclient is a pure Python library that abstracts HTTP calls for various ownCloud APIs. It supports ownCloud versions 8.2, 9.0, 9.1, and newer.

    Core Capabilities:

    • File Operations: Directory listings, upload/download (including chunking and mtime preservation), directory creation, uploading whole directories, downloading directories as ZIP, and reading/writing file contents from strings.
    • Sharing (OCS Share API): Creating/unsharing public links, sharing with users or groups, checking share status, and updating share properties.
    • Provisioning (OCS Provisioning API):
      • Apps: Enabling/disabling apps and listing enabled apps.
      • Users: Creating/deleting users and groups, and managing user group membership.
    • App Data: Storing key/value app data via the privatedata OCS API.
    • Instance Info: Retrieving version, host, and URL information.
  2. Basic usage of pyocclient

    master

    To use the library, initialize an owncloud.Client with your ownCloud instance URL and authenticate using login(). The client provides high-level abstractions for file operations and directory management, removing the need to handle HTTP or WebDAV calls manually.

    import owncloud
    
    # Initialize the client with your server URL
    oc = owncloud.Client('http://your-owncloud-instance.example.com/')
    
    # Authenticate
    oc.login('user', 'password')
    
    # Upload a file to a remote path
    oc.put_file('remote/path/file.txt', 'local/file.txt')
    
    # List items in a directory
    for item in oc.list('/'):
        print(item)
  3. Access files via public links

    master

    pyocclient provides specialized methods to interact with public shared folders without standard user credentials.

    Use owncloud.Client.from_public_link(public_link) and the drop_file method.

    Use owncloud.Client.from_public_link(public_link, folder_password=folder_password) and the get_file method.

    import owncloud
    
    # Uploading to a public link
    public_link = 'http://domain.tld/owncloud/A1B2C3D4'
    oc = owncloud.Client.from_public_link(public_link)
    oc.drop_file('myfile.zip')
    
    # Downloading from a password-protected public link
    public_link = 'http://domain.tld/owncloud/A1B2C3D4'
    folder_password = 'secret'
    oc = owncloud.Client.from_public_link(public_link, folder_password=folder_password)
    oc.get_file('/sharedfile.zip', 'download/destination/sharedfile.zip')
  4. Basic usage: Upload and share a file

    master

    To interact with a private ownCloud instance, instantiate owncloud.Client with your server URL, log in with credentials, and use methods like mkdir, put_file, and share_file_with_link.

    Note: This library is a functional abstraction for APIs and is not a sync client implementation.

    import owncloud
    
    oc = owncloud.Client('http://domain.tld/owncloud')
    
    oc.login('user', 'password')
    
    oc.mkdir('testdir')
    
    oc.put_file('testdir/remotefile.txt', 'localfile.txt')
    
    link_info = oc.share_file_with_link('testdir/remotefile.txt')
    
    print "Here is your link: " + link_info.get_link()