Nextcloud Python API
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
- breaking The library switched its underlying HTTP client from `httpx` to `niquests`. If your code had deep integrations, custom client configurations, or relied on `httpx` specific exceptions/behavior, it might break.
- deprecated The `/apps/status/{appId}` endpoint for setting Nextcloud App status has been deprecated. The library now uses the `/ex-app/status` endpoint.
- gotcha When developing a Nextcloud App, use `NextcloudApp` which gets its context from Nextcloud. For standalone scripts or external clients, use `Nextcloud` and provide explicit connection details (URL, app password/username). Mixing these can lead to incorrect behavior or connection issues.
- gotcha Error handling for external model downloads (e.g., in ExApps) has changed. If there's an error during a model download, an exception is now explicitly raised to prevent incorrect or partial ExApp installations.
Install
-
pip install nc-py-api
Imports
- Nextcloud
from nc_py_api import Nextcloud
- NextcloudApp
from nc_py_api import NextcloudApp
Quickstart
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}")