Skip to main content

Python client library for KCFinder file manager

Project description

kcfinder-client

CI Python 3.14+ 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())

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.0.tar.gz (54.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.0-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: kcfinder_client-0.2.0.tar.gz
  • Upload date:
  • Size: 54.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.0.tar.gz
Algorithm Hash digest
SHA256 cb142434270b10b866a72aa92114fb965d9f7baa66700a6a334babfa613c115e
MD5 e7920e00efcdece5344121e65854c120
BLAKE2b-256 c0d757026040de0132777dd2d9700d79c8d786c1348040ae1dda412cc3a8131f

See more details on using hashes here.

Provenance

The following attestation bundles were made for kcfinder_client-0.2.0.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.0-py3-none-any.whl.

File metadata

  • Download URL: kcfinder_client-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 14.7 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9aa5f3226aef675f60a0c42f73216a542800fd4325b6dc9bce497597f92946c9
MD5 353b43fc933c3549e9a39f414358f8d5
BLAKE2b-256 e4eb4c2ea9d319b5243989fc3196acc911b962bb8dbd2cbf911d34cfb8a9d29f

See more details on using hashes here.

Provenance

The following attestation bundles were made for kcfinder_client-0.2.0-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