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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file minidir-0.1.3.tar.gz.

File metadata

  • Download URL: minidir-0.1.3.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.3

File hashes

Hashes for minidir-0.1.3.tar.gz
Algorithm Hash digest
SHA256 072fb532bdca0d9a85dac111eac74cb8657d74de65a79f023ce0fbcfc3496e8a
MD5 244e27044078fb7e67d6efd2ff96d93e
BLAKE2b-256 a73810f2ccedbd8cc9b5d7f8f8366944472da640e55f8bccb10eeae39879e324

See more details on using hashes here.

File details

Details for the file minidir-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: minidir-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 3.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.3

File hashes

Hashes for minidir-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 558f64b1967f4a674039491b4f719e7f400d0c541026dd156f0d6ea4602c4c20
MD5 c01dbbbf2ca9136a31ee6eaec67d0c14
BLAKE2b-256 c757a5244323c0208e7437ef05093e7a3acc7cbce0747d6ff72ccd9bbd7ec6af

See more details on using hashes here.

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