Skip to main content

Minimal directory interface and some implementations

Project description

minidir: Minimal directory interface and implementation

The minimal interface for directories and files and two implementations: in-memory and real file system versions.

It's a good choice when we want to separate file-access side effects from pure functional part of our code base.

Installation

Already published on Pypi

pip install minidir

Usage

  • Interface: Directory -> Path, File
    • Directory is the container where we access File by Path
  • Implementation
    • SystemDirectory: a Directory backed by real file system.
    • FakeDirectory: a Directory only exists in-memory.

Some error like NameCollision and NotFound will be raised in corresponding situations.

Example:

import minidir

class SomeClass:
    folder: minidir.Directory

    def __init__(self, folder: minidir.Directory) -> None:
        # inject directory to separate side effect from core logic
        pass

def main():
    # use actual file system during production
    instance = SomeClass(minidir.SystemDirectory("/path/to/root"))

def test_some_class():
    # use in-memory implementation during test
    instance = SomeClass(minidir.FakeDirectory())

Future Work

  • Implementations for network-oriented storage, e.g. WebDAV, S3, Dropbox ...
  • Stream based file read / write interface.

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

minidir-0.1.3.tar.gz (4.5 kB view hashes)

Uploaded Source

Built Distribution

minidir-0.1.3-py3-none-any.whl (3.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page