Skip to main content

Python file and zip operations made easy

Project description

Flametree is a Python library which provides a simple syntax for handling files and folders (no os.path.join, os.listdir etc.), and works the same way for different file systems.

Write a Flametree program to read/write files in disk folders, and your code will also be able to read/write in zip archives and virtual (in-memory) archives - which is particularly useful on web servers.

As an illustration, here is how to use Flametree to read a file texts/poems/the_raven.txt, replace all occurences of the word “raven” by “seagull” in the text, and write the result to a new file the_seagull.txt in the same folder:

from flametree import file_tree

with file_tree("texts") as root:
    poem_text = root.poems.the_raven_txt.read()
    new_text = poem_text.replace("raven", "seagull")
    root.poems._file("the_seagull.txt").write(new_text)

Even in this very simple use case, the syntax is clearer than the os way, which would write as follows:

import os

with open(os.path.join("poems", "the_raven.txt"), "r") as f:
    poem_text = f.read()
new_text = poem_text.replace("raven", "seagull")
with open(os.path.join("poems", "the_seagull.txt"), "w") as f:
    content = f.write(new_text)

Moreover, the same Flametree code also works for files inside a zip archive:

with file_tree("my_archive.zip") as root:
    poem_text = root.poems.the_raven_txt.read()
    new_text = poem_text.replace("raven", "seagull")
    root.poems._file("the_seagull.txt").write(new_text)

Now in hard mode: suppose that your server receives binary zip data of an archive containing poems/the_raven.txt, and must return back a new zip containing a file poems/the_seagull.txt. Here again, the syntax of the core operations is the same:

destination_zip = file_tree("@memory") # Create a new virtual zip
with file_tree(the_raven_zip_data) as root:
    poem_text = root.poems.the_raven_txt.read()
    new_text = poem_text.replace("raven", "seagull")
    destination_zip._dir("poems")._file("the_seagull.txt").write(new_text)
destination_zip_data = destination_zip._close()
# Now send the data to the client

See section Usage below for more examples and features.

Infos

PIP installation:

pip install flametree

Github Page: https://github.com/Edinburgh-Genome-Foundry/Flametree

License: MIT

Copyright 2017 Edinburgh Genome Foundry, University of Edinburgh

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

flametree-0.2.1.tar.gz (13.6 kB view details)

Uploaded Source

Built Distribution

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

flametree-0.2.1-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: flametree-0.2.1.tar.gz
  • Upload date:
  • Size: 13.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for flametree-0.2.1.tar.gz
Algorithm Hash digest
SHA256 51fde0d6b4f298d429dfaabe87b05b517352ca340f510a9aceee8e1fce34620e
MD5 bf5fc42331f7141cefdfea83f5a3dd29
BLAKE2b-256 47a02b818b9ca5b2bdcc18a196b986f8efebf66a20a94e0d239a402e75e9a1a1

See more details on using hashes here.

Provenance

The following attestation bundles were made for flametree-0.2.1.tar.gz:

Publisher: publish.yml on Edinburgh-Genome-Foundry/Flametree

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

File details

Details for the file flametree-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: flametree-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for flametree-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 abe29a309e8ab9bbb5a6777ab5a1c88b248565067861a82189fc361866eb73e0
MD5 30d5c122e838b4edd3e568cbe66d51bb
BLAKE2b-256 ec47310b1ac5e68da42680d24b2d2712989c0362270eeec2adf59886826af836

See more details on using hashes here.

Provenance

The following attestation bundles were made for flametree-0.2.1-py3-none-any.whl:

Publisher: publish.yml on Edinburgh-Genome-Foundry/Flametree

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