Skip to main content

Python client library for KCFinder file manager

Project description

kcfinder-client

CI Python 3.12+ License: MIT

A Python client library for KCFinder, a PHP web file manager. Wraps KCFinder's HTTP action-dispatch API into a clean Python interface with both async and sync clients.

[!NOTE] Designed for and tested against HarmonySite's KCFinder fork. May work with other KCFinder instances via SessionAuth, but this has not been tested.

Table of Contents

Install

# uv
uv add kcfinder-client

# pip
pip install kcfinder-client

Quick Start

Async (recommended)

import asyncio
import os
from kcfinder_client import AsyncKCFinderClient, HarmonySiteAuth

auth = HarmonySiteAuth(
    login_url="https://example.harmonysong.com/dbaction.php",
    browse_url="https://example.harmonysong.com/kcfinder/browse.php",
    username="admin",
    password="secret",
    bros_config=(
        'a:3:{s:9:"uploadDir";s:6:"files/";'
        's:9:"thumbsDir";s:14:"files/.thumbs/";'
        's:9:"uploadURL";s:0:"";}'
    ),
)

async def main():
    browse_url = "https://example.harmonysong.com/kcfinder/browse.php"
    async with AsyncKCFinderClient(browse_url, auth) as client:
        files = await client.list_files("banners")
        for f in files:
            print(f.name, f.size)

asyncio.run(main())

Sync

from kcfinder_client import KCFinderClient, HarmonySiteAuth

auth = HarmonySiteAuth(
    login_url="https://example.harmonysong.com/dbaction.php",
    browse_url="https://example.harmonysong.com/kcfinder/browse.php",
    username="admin",
    password="secret",
    bros_config=(
        'a:3:{s:9:"uploadDir";s:6:"files/";'
        's:9:"thumbsDir";s:14:"files/.thumbs/";'
        's:9:"uploadURL";s:0:"";}'
    ),
)

browse_url = "https://example.harmonysong.com/kcfinder/browse.php"
with KCFinderClient(browse_url, auth) as client:
    files = client.list_files("banners")
    for f in files:
        print(f.name, f.size)

Auth from Environment Variables

Load credentials from the environment rather than hardcoding them:

export KCFINDER_LOGIN_URL=https://example.harmonysong.com/dbaction.php
export KCFINDER_BROWSE_URL=https://example.harmonysong.com/kcfinder/browse.php
export KCFINDER_USERNAME=admin
export KCFINDER_PASSWORD=secret
export KCFINDER_BROS_CONFIG='a:3:{s:9:"uploadDir";s:6:"files/";s:9:"thumbsDir";s:14:"files/.thumbs/";s:9:"uploadURL";s:0:"";}'
import os
from kcfinder_client import AsyncKCFinderClient, harmonysite_auth_from_env
import asyncio

async def main():
    auth = harmonysite_auth_from_env()
    browse_url = os.environ["KCFINDER_BROWSE_URL"]
    async with AsyncKCFinderClient(browse_url, auth) as client:
        files = await client.list_files()
        print(f"Found {len(files)} files")

asyncio.run(main())

Timeouts & Retries

Both clients accept optional timeout and retries parameters:

from kcfinder_client import KCFinderClient

# Set a 30-second timeout
with KCFinderClient(browse_url, auth, timeout=30.0) as client:
    files = client.list_files()

# Retry up to 3 times on connection errors and 5xx responses
with KCFinderClient(browse_url, auth, retries=3) as client:
    files = client.list_files()

# Both together
with KCFinderClient(browse_url, auth, timeout=30.0, retries=3) as client:
    files = client.list_files()
  • timeout — passed to the underlying httpx client. Accepts a float (seconds) or an httpx.Timeout object for fine-grained control. Defaults to the httpx default of 5 seconds.
  • retries — number of retry attempts for transient failures (connection errors and HTTP 5xx responses). Uses exponential backoff between attempts. Defaults to 0 (no retries). Uploads are never retried.

Sync Files with SyncManager

One-way push sync to make a remote directory match a local one:

import os
from pathlib import Path
from kcfinder_client import KCFinderClient, SyncManagerSync, harmonysite_auth_from_env

auth = harmonysite_auth_from_env()
browse_url = os.environ["KCFINDER_BROWSE_URL"]

with KCFinderClient(browse_url, auth) as client:
    sync = SyncManagerSync(client)

    # Dry run first to preview changes
    result = sync.push("banners", Path("./banners"), dry_run=True)
    print(f"Would upload: {result.uploaded}")
    print(f"Would delete: {result.deleted}")
    print(f"Would skip:   {result.skipped}")

    # Apply the sync
    result = sync.push("banners", Path("./banners"))

Documentation

License

MIT

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

kcfinder_client-0.2.2.tar.gz (67.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kcfinder_client-0.2.2-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

Details for the file kcfinder_client-0.2.2.tar.gz.

File metadata

  • Download URL: kcfinder_client-0.2.2.tar.gz
  • Upload date:
  • Size: 67.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for kcfinder_client-0.2.2.tar.gz
Algorithm Hash digest
SHA256 b85c17b71fc75b645632c27dc9c31bcf978dac3fae6151bbc1861e2269696a46
MD5 c114828614733f2b8f1604a549680e20
BLAKE2b-256 ad469073230d3d6444f9750f414831954a550a1b7b72b576e6ef7753aee08350

See more details on using hashes here.

Provenance

The following attestation bundles were made for kcfinder_client-0.2.2.tar.gz:

Publisher: publish.yml on cyberops7/kcfinder-client

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file kcfinder_client-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: kcfinder_client-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 16.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for kcfinder_client-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2d84aad5683d709889f21f0470dd244310cc10293f5127e1d1a3c4ef6c9566a0
MD5 1f97514949d26223fa21c538c3aabd24
BLAKE2b-256 be5e2377cf5fee630a3371958fb23d9c71b1c221f95fc1d0fca6fe635fbe6110

See more details on using hashes here.

Provenance

The following attestation bundles were made for kcfinder_client-0.2.2-py3-none-any.whl:

Publisher: publish.yml on cyberops7/kcfinder-client

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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