Nextcloud Python API

0.30.0 · active · verified Sat Apr 11

nc-py-api is the official Python Framework for interacting with Nextcloud instances, enabling both client-side operations and the development of Nextcloud applications. It provides a comprehensive API for various Nextcloud features including users, files, and declarative settings. The current version is 0.30.0, and the library maintains an active release cadence with frequent updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to connect to a Nextcloud instance using the `Nextcloud` client and retrieve information about the current user. It's recommended to use environment variables for sensitive credentials.

import os
from nc_py_api import Nextcloud

NEXTCLOUD_URL = os.environ.get('NEXTCLOUD_URL', 'https://nextcloud.example.com')
NEXTCLOUD_APP_PASS = os.environ.get('NEXTCLOUD_APP_PASS', 'your_app_password') # or username/password

if NEXTCLOUD_URL == 'https://nextcloud.example.com' or NEXTCLOUD_APP_PASS == 'your_app_password':
    print("Please set NEXTCLOUD_URL and NEXTCLOUD_APP_PASS environment variables or replace placeholders.")
else:
    try:
        nc = Nextcloud(
            nextcloud_url=NEXTCLOUD_URL,
            nextcloud_app_pass=NEXTCLOUD_APP_PASS
        )
        current_user = nc.users.get_current_user()
        print(f"Connected to Nextcloud as user: {current_user.user_id}")
        print(f"Display name: {current_user.display_name}")
    except Exception as e:
        print(f"Failed to connect or fetch user info: {e}")

view raw JSON →