Skip to main content

An experimental and GitLab filesystem extension for PyFilesystem2.!

Project description

ARCfs

ARCfs is a experimental implementation of a PyFilesystem2 filesystem abstraction for GitLab.
Through this, ARCfs provides a filesystem-like view of DataPLANT DataHUB ARCs in Python.

Installation

ARCfs is available as pip package.

pip install gitlab-arc-fs

Alternatively:

  1. Download / clone Repository
  2. Change directory into ARCfs
  3. Run pip install .

NOTE: For read acces, an API token with the scope "read_api" is sufficient. For write access the scope "api" is requiered. You can find more information here.

Getting started

Creating an ARCfs object

To create an ARCfs object directly, you can use the following Code.

from gitlab_arc_fs.arc_fs import ARCfs

# To use the DataHUB GitLab Server: "https://git.nfdi4plants.org/"
server_url = "<URL_to_GitLab_Server>"
access_token = "<GitLab_API_access_token>"

arc_fs = ARCfs(access_token, server_url)

FS URLs

Useful for creating filesystems from a configuration file or the command line. Creates an instance of ARCfs with a URL comparable to one you would use in a browser.

from fs import open_fs

arc_fs = open_fs("arcfs://<GitLab_API_access_token>@<URL_to_GitLab_Server>")

The open_fs() function can also be used as context manager:

from fs import open_fs

with open_fs("arcfs://<GitLab_API_access_token>@<URL_to_GitLab_Server>") as arc_fs:
    # Do something with arc_fs here.

Usage

Bellow some examples how an ARCfs instance can be used.

List directory content:

# list all ARCs / repos a user has access to (with the given API token).
arcs = arc_fs.listdir("/")

# list files/dirs inside a repository
files = arc_fs.listdir("<namespace>-<reponame>/<path_inside_repository>")

NOTE: In the <namespace> part, replace "." with "_", e.g. "firstname.lastname" -> "firstname_lastname".

Open/Download a file

# using fs.open
with open("<local_path>", "wb") as local_file:
    with arc_fs.open("<remote_path>", mode="rb") as remote_file:
        for byte in iter(lambda: remote_file.read(4096), b""):
            local_file.write(byte)

# using fs.download
with open("<local_path>", "wb") as local_file:
    arc_fs.download("<remote_path>", local_file)

Creating directories and uploading files

with open("<local_path>", "rb") as local_file:
    if not arc_fs.isdir("<remote_path>"):
        openfs.makedirs("<remote_path>")
    # It would also be possible to open a remote file in write modus,
    # but the upload function is preferable.
    arc_fs.upload("<remote_path>", local_file)

NOTE: Since GitLab has no real concept of directories, a newly created directory does not become permanent until a file is placed in that directory.

More information about the PyFilesystem API can be founde here.

Further important information

ARCfs does not support setting file information nor the deletion of directories or files (setinfo(), remove(), removedir()).

Upon performing any write operation with ARCfs, the file in question is uploaded as LFS file, a new branch is created and pointer file is commited in the newly created branch. Finally, a merge request into the main branch is created.

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

gitlab_arc_fs-0.0.26.dev1.tar.gz (35.0 kB view details)

Uploaded Source

Built Distribution

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

gitlab_arc_fs-0.0.26.dev1-py3-none-any.whl (33.6 kB view details)

Uploaded Python 3

File details

Details for the file gitlab_arc_fs-0.0.26.dev1.tar.gz.

File metadata

  • Download URL: gitlab_arc_fs-0.0.26.dev1.tar.gz
  • Upload date:
  • Size: 35.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.2

File hashes

Hashes for gitlab_arc_fs-0.0.26.dev1.tar.gz
Algorithm Hash digest
SHA256 e10c59a9858d50efc71711a6115fe869d8c1aa9cdfb2463f7b25b1d789afb631
MD5 b18e86052a67d5817090d17d25929854
BLAKE2b-256 857ab28743f1d5da2e4203d18ec22047ccf61d780af3f77ddea9822a3199ce81

See more details on using hashes here.

File details

Details for the file gitlab_arc_fs-0.0.26.dev1-py3-none-any.whl.

File metadata

File hashes

Hashes for gitlab_arc_fs-0.0.26.dev1-py3-none-any.whl
Algorithm Hash digest
SHA256 78bf29e686361eedf92eddf22e8560ef24b77f8ae72a7f4e0ffd209a39ded1b9
MD5 a6ce0ad4243c1815c0d5f61e5f516b19
BLAKE2b-256 ce4c02511ad0e0e3117d905cb1f312ddb960c85782ae167aa3e46634a76e65b1

See more details on using hashes here.

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