Skip to main content

Static Folders

The premise for this library is simple: you want a statically typed way to refer to a catalogue of data.

Why would you want this?

Let's start with some alternatives I've seen to managing this problem this:

from Pathlib import Path
data_dir = Path("d:/projects/<project>/data") # person A
# data_dir = Path("/mnt/data/projects/<project>/data") # person B
config = data_dir / "config.json"
regression_inputs_csv = data_dir / "regression_model"/"input.csv"

There are a few pain points here:

  1. Code you need to swap out depending on which machine things are being run on, which often tends to end up across multiple notebooks (this is not something this library solves, but having a reusable folder structure encourages one to thing about having a more centralised mechanism to manage these kinds of things, rather that commented code in scripts)
  2. You can end up with a lot of variables quickly if you have lots of files
  3. If you want to compose pieces with constants you end up with even more variables
  4. No autocompletion from an editor
  5. If you ever need to move a file you're reliant on find+replace / regex to make sure you update all the usages ( which becomes more error-prone as you try to reuse path pieces, as the there are more text replacement variants )

A solution to this is some kind of wrapper class:

@define
class ApplicationPaths:
    root: Path
    
    def get_config(self)->Path:
       ...

This works fine, but you get no structure around the internals, only an external API which is statically typed. The same issues persist around changing your data representation, and if you want to specify detail within a nested subpath, you end up with a lot of methods, which can become unwieldly.

Static Folders provides a type-checked interface to represent a folder tree:

from pathlib import Path
from static_folders import Folder

class RegressionModelData(Folder):
    input_csv: Path = Path("input.csv")
  

class ApplicationData(Folder):
    regression_model_data: RegressionModelData = RegressionModelData("regression_model_data")
    config: Path = Path("config.json")

app_root = ApplicationData("d:/projects/<project>/data")
print(app_root.regression_model_data.input_csv.read_text())

We also provide some convenience inference based on type annotations, to reduce the amount of boilerplate being written - we could equivalently write the above class as:

class ApplicationData(Folder):
    regression_model_data: RegressionModelData
    config: Path = Path("config.json")

for the same result.

Why are you hard coding file paths, shouldn't your code be more modular?

Sometimes it's quite useful to be able to explicitly refer to a catalog of data inputs e.g.

  • Data science / analytics or processing pipelines
  • GIS data transformations
  • For complicated applications with quite specific input requirements e.g. transport models

That doesn't mean you should write your code coupled to Folder instances, you can (and probably should) still seperate business logic from data representation. There's a similar concept well explained in the cattrs documentation - that the serialisation of your data model should be a decoupled concern from the data model itself. In the same way, static folders deals with the data representation of your inputs, which should be seperate from how your code actually processes data.

But what if I have data on the cloud / stored in some way that doesn't fit this model?

  • If your data is sufficiently small, you might be able to mirror the data (this can be quite useful working in a transport modelling ecosystem where inspecting and checking input and output files independently of code can be very valuable, and having an explicit mirror makes things easy to find)
  • If not, or you're intrinsically coupled to cloud storage, then static folders probably isn't a good fit.

Metadata

Release files for static-folders 0.3.0

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

Source distribution (sdist)

Source distribution for static-folders 0.3.0
File Size Uploaded Provenance Actions
static_folders-0.3.0.tar.gz 42.9 kB With provenance Details for static_folders-0.3.0.tar.gz

Built distribution (wheel)

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

Total release size: 51.8 kB

Release files / static_folders-0.3.0.tar.gz

Download URL static_folders-0.3.0.tar.gz
Size 42.9 kB
Tags Source
SHA-256 checksum
How to use checksums
554df4290392c4f7b2d23c23ef6b53e96c2647a86faa10194a0f1b06e415d56b
BLAKE2b-256 checksum
How to use checksums
4cd4600ab464ac1fcbdeea4ce86eb09827df4a1998541140de3978e973f79d70
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 23, 2025.

Transparency log

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

Download URL static_folders-0.3.0-py3-none-any.whl
Size 8.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7fce2e53034dfdb9e56cd5933759309ee9313e221ae23c21034ced8fb4adcc38
BLAKE2b-256 checksum
How to use checksums
e9373a7e844ff1684e98144b31412ba1bc13894537027a43e70d38153c1efd46
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 23, 2025.

Transparency log

Security for static-folders 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for static_folders-0.3.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 23, 2025.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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