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.1.tar.gz (55.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.1-py3-none-any.whl (14.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: kcfinder_client-0.2.1.tar.gz
  • Upload date:
  • Size: 55.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.1.tar.gz
Algorithm Hash digest
SHA256 cd101d95950a3f3ecc18b096e841cd905af5de1579b4aaf5ab0d7e260a1e8a22
MD5 0fbc4848e76f187f6b80212f14e6cc52
BLAKE2b-256 738f6c012196feb2bda788c6d91ba6ee2e1ba0c582867565b9d13590c614c9ec

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: kcfinder_client-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 14.9 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2de1b960b33e1a09f993ff8802fcbb39182dad4c0b278784e140711fe7d6e7bc
MD5 53e3b27e250dda34415bad75be147042
BLAKE2b-256 65bfe767ba924ce85ef07e6c5160c3ea5b631360f69647e64a4106bad78151af

See more details on using hashes here.

Provenance

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