Provides ORM path classes (File and Dir), which automatically emit file system IO operations upon having their attributes modified. File objects allow for easy content manipulation of many forms of files.
This library is currently still under development. The API will likely undergo significant changes that may break any code you write with it. The documentation will fall out of sync with the updates regularly until development slows down. Use it at your own risk.
Pathmagic implements two classes, File
and Dir
, to represent mapped file system obects in a manner similar to database ORMs like sqlalchemy. These objects have properties which
perform file system operations when set, and implement many useful methods to abstract away nearly all file system I/O to a much higher degree than os.path
or pathlib
.
Dir
classDir.path
, Dir.parent
, Dir.name
)Dir.files
, Dir.dirs
) which allow iteration over their respective collections, item access, membership tests, and moreDir.d
, Dir.f
), which dynamically populate themselves with snake_cased attributes that represent the files/folders in their Dir
, such that
the filesystem tree can be traversed purely through attribute accessFile
classProperties that perform rename and move operations when set (File.path
, File.dir
, File.name
,
File.stem
, File.extension
)
Methods to copy/move self to another path/dir or delete self
Initialize from script entry point (in traditional interpreter), and from a package resource
File.read()
and File.write()
methods (and associated File.content
property) which invokes the FormatHandler
class to determine how to read from/write to the file based
on its extension. FormatHandler
uses the factory design pattern and can be extended at runtime to enable File
to handle types of files that are not supported by default.
By default, recognized formats are the following:
format | class accepted/returned | file extensions |
---|---|---|
PyPDF2 | ||
Tabular | subtypes.Frame | xlsx, csv |
Word | docx.Document | docx |
Image | PIL.Image | png, jpf, jpeg |
Audio | pydub.AudioSegment | mp3, wav, ogg, flv |
Video | Moviepy.editor.edit | mp4, mkv, avi, gif |
Compressed | pathmagic.Dir | zip, tar |
Link | pathmagic.File or pathmagic.Dir | lnk |
Serialized | Any | pkl |
Json | Any | json |
MarkUp | subtypes.Markup | html, xml |
Default | subtypes.Str | everything else |
To install use pip:
$ pip install pathmagic
Or clone the repo:
$ git clone https://github.com/matthewgdv/pathmagic.git
$ python setup.py install
Detailed usage examples coming soon.
Contributions are welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given.
You can contribute in many ways:
Report bugs at https://github.com/matthewgdv/pathmagic/issues
If you are reporting a bug, please include:
Look through the GitHub issues for bugs. Anything tagged with "bug" and "help wanted" is open to whoever wants to implement a fix for it.
Look through the GitHub issues for features. Anything tagged with "enhancement" and "help wanted" is open to whoever wants to implement it.
The repository could always use more documentation, whether as part of the official docs, in docstrings, or even on the web in blog posts, articles, and such.
The best way to send feedback is to file an issue at https://github.com/matthewgdv/pathmagic/issues.
If you are proposing a new feature:
Before you submit a pull request, check that it meets these guidelines:
If the pull request adds functionality, it should include tests and the docs should be updated. Write docstrings for any functions that are part of the external API, and add the feature to the README.md.
If the pull request fixes a bug, tests should be added proving that the bug has been fixed. However, no update to the docs is necessary for bugfixes.
The pull request should work for the newest version of Python (currently 3.7). Older versions may incidentally work, but are not officially supported.
Inline type hints should be used, with an emphasis on ensuring that introspection and autocompletion tools such as Jedi are able to understand the code wherever possible.
PEP8 guidelines should be followed where possible, but deviations from it where it makes sense and improves legibility are encouraged. The following PEP8 error codes can be safely ignored: E121, E123, E126, E226, E24, E704, W503
This repository intentionally disallows the PEP8 79-character limit. Therefore, any contributions adhering to this convention will be rejected. As a rule of thumb you should endeavor to stay under 200 characters except where going over preserves alignment, or where the line is mostly non-algorythmic code, such as extremely long strings or function calls.