Skip to main content

Deployments

Python

pypi

none-shall-pass

book

docker

PyPI version shields.io Pypi-format Pypi-status

PyFileBrowser

pyfilebrowser is a Python library designed to streamline interactions with filebrowser

This wrapper simplifies integration and automation tasks, enabling seamless interaction with local file system via filebrowser's web interface.

All the required configuration, settings, and user profiles are loaded using .env files. This provides a more centralized way of handling the configuration and initialization.

pyfilebrowser automatically downloads the system specific executable during startup.

Download custom-built executables

Additionally, custom source (to download binaries) can be configured by specifying the following environment variables

  • OWNER - Owner of the GitHub repo.
  • REPO - Repository name.
  • TOKEN - GitHub repository token.
  • VERSION - Version of the release.

Automatically sourced from .github.env if available

For this custom source feature to work, the executable should be uploaded to releases as assets, and follow the naming convention below.

asset naming convention: ${operating system}-{architecture}-filebrowser-{extension}
example: darwin-amd64-filebrowser.tar.gz

Kick Off

Install

python -m pip install pyfilebrowser

Initiate [programmatically]

import pyfilebrowser

if __name__ == '__main__':
    browser = pyfilebrowser.FileBrowser()
    # browser.proxy = True  # [Optional] Enables proxy server to run in parallel
    browser.start()

Initiate [CLI]

pyfilebrowser

Environment Variables

Env vars can either be loaded from .env files or directly passed during object init.

.env files

proxy server

.proxy.env - Loads the proxy server's configuration.

  • host str - Hostname/IP for the proxy server. Defaults to socket.gethostbyname('localhost')
  • port int - Port number for the proxy server. Defaults to 8000
  • workers int - Number of workers used to run the proxy server. Defaults to 1
  • debug bool - Boolean flag to enable debug level logging. Defaults to False
  • origins List[str] - Origins to allow connections through proxy server. Defaults to host
  • allow_public_ip bool - Boolean flag to allow public IP address of the host. Defaults to False
  • allow_private_ip bool - Boolean flag to allow private IP address of the host. Defaults to False
  • origin_refresh int - Interval in seconds to refresh all the allowed origins. Defaults to None
  • rate_limit - Dict/List[Dict] with the rate limit for the proxy server. Defaults to None
  • unsupported_browsers - List[str] with a list of unsupported browsers. Defaults to Chrome
  • warn_page FilePath - Warning page to serve when accessed from Unsupported browsers. Defaults to warn.html
  • error_page FilePath - Error page to serve when filebrowser API is down. Defaults to error.html

origin_refresh allows users to set a custom interval to update the public and private IP address of the host, based on their DHCP lease renewal.
This is specifically useful in cases of long-running server sessions.

filebrowser configuration

.config.env - Loads the server's default configuration. Reference: config

Extra configuration settings can be loaded using a JSON/YAML file. These settings will be merged with the default configuration settings. The filename can either be passed as extra_env during object instantiation [OR] through an environment variable pyfb_extra_env key. Reference: extra_env

filebrowser user profiles

.user*.env - Loads each user's profile specific configuration. Reference: users

Multiple user profiles can be loaded using .user1.env, .user2.env and so on.
User profile's permissions are automatically set based on the admin flag set in the env-var authentication

filebrowser binary/executable

.github.env - Loads GitHub config to download the filebrowser executable/binary.

.env files can be placed in a dedicated directory, whose path can be set using the env var SECRETS_PATH before importing pyfilebrowser

Example

Sample directory structure

root (current working directory)
  ├ secrets
  | ├ .config.env
  | ├ .github.env
  | ├ .proxy.env
  | ├ .user1.env
  | └ .user2.env
  ├ venv/
  └ main.py

Set custom location for secrets [programmatically]

import os

os.environ["secrets_path"] = os.path.join(os.getcwd(), "secrets")

import pyfilebrowser
...

[OR]

Set custom location for secrets [CLI]

export secrets_path="secrets"

pyfilebrowser run

Refer samples directory for sample .env files. For nested configuration settings, refer the runbook

Any configuration changes made in the UI will be lost, unless backed up manually.
Changes should always go through the .env files.

Object level instantiation is also possible, but not recommended
from pyfilebrowser import FileBrowser

if __name__ == '__main__':
    file_browser = FileBrowser(
        user_profiles=[
            {"authentication": {"username": "admin", "password": "admin", "admin": True}},
            {"authentication": {"username": "user123", "password": "pwd456", "admin": False}}
        ]
    )
    file_browser.start()

Object level instantiation might be complex for configuration settings. So it is better to use .env files instead.

Proxy Server

pyfilebrowser allows you to run a proxy server in parallel, which includes a collection of security features and trace level logging information.

Enabling proxy server increases an inconspicuous latency to the connections, but due to asynchronous functionality, it is hardly noticeable.
The proxy server is designed to be lightweight and efficient, however streaming large video files may increase the memory usage at server side, due to multi-layered buffering.

Firewall

While CORS may solve the purpose at the webpage level, the built-in proxy's firewall restricts connections from any origin regardless of the tool used to connect (PostMan, curl, wget etc.)

Due to this behavior, please make sure to specify ALL the origins that are supposed to be allowed (including but not limited to reverse-proxy, CDN, redirect servers etc.)

Brute Force Protection

  • The built-in proxy service limits the number of failed login attempts from a host address to three.
  • Any more than 3 attempts, will result in the host address being temporarily blocked.
  • For every failed attempt (after the initial 3), the host address will be blocked at an incremental rate.
  • After 10 such attempts, the host address will be permanently (1 month) forbidden.

Rate Limiter

The built-in proxy service allows you to implement a rate limiter.

Rate limiting allows you to prevent DDoS attacks and maintain server stability and performance.

Brute force protection and rate limiting are reset when the server is restarted.

Coding Standards

Docstring format: Google
Styling conventions: PEP 8 and isort

Release Notes

Requirement

pip install gitverse

Usage

gitverse-release reverse -f release_notes.rst -t 'Release Notes'

Linting

pre-commit will ensure linting, and generate runbook

Requirement

pip install sphinx==5.1.1 pre-commit recommonmark

Usage

pre-commit run --all-files

Pypi Package

pypi-module

https://pypi.org/project/pyfilebrowser/

Runbook

made-with-sphinx-doc

https://thevickypedia.github.io/pyfilebrowser/

© Vignesh Rao

Licensed under the MIT License

Release files for pyfilebrowser 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for pyfilebrowser 0.3.0
File Interpreter ABI Platform
pyfilebrowser-0.3.0-py3-none-any.whl Python 3 none any Details

Release files / pyfilebrowser-0.3.0-py3-none-any.whl

Download URL pyfilebrowser-0.3.0-py3-none-any.whl
Size 45.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
18489e896b5f7afbe8228426ead8381a44f11390b550080cc69a2678ef5003c9
BLAKE2b-256 checksum
How to use checksums
382100de6e86417bb4b976af9bd6718f99f093c511c8f2e9fabe1f50f3f276e6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.0rc1

Release history Release notifications | RSS feed

This release

0.3.0 This release

1 release file

0.2.3

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2.0

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

0.0.91

1 release file

0.0.9

1 release file

0.0.8

1 release file

0.0.7

1 release file

0.0.4

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page