Package: pyminio
PyminioPyminio is a python client wrapped like theosmodule to control minio server.I have developed pyminio while trying to work with the minio's original python client with a lot of struggles. I had to read and understand minio's implementations to preform the most simple tasks.Pyminio is a wrapper to minio, that is more indecative for the user.
It works likeosmodule, so you don't need to understand minio's concepts, and just using regular paths.ContentInstallationSetting up PyminioUsageContributeInstallationUse the package managerpipto install pyminio.pipinstallpyminioorgitclonehttps://github.com/mmm1513/pyminio.gitcdpyminio
pythonsetup.pyinstallSetting up PyminioFirstly you need to set up yourMinio Docker, and acquire an ENDPOINT (URL), ACCESS_KEY, and a SECRET_KEY.If you want to add your own minio object you can pass it in the constructor like so:Install python'sMiniomodule.fromminioimportMiniofrompyminioimportPyminiominio_obj=Minio(endpoint='<your-minio-endpoint>',# e.g. "localhost:9000/"access_key='<your-minio-access-key>',secret_key='<your-minio-secret-key>')pyminio_client=Pyminio(minio_obj=minio_obj)If you don't want to handle with minio, you can do this instead:frompyminioimportPyminiopyminio_client=Pyminio.from_credentials(endpoint='<your-minio-endpoint>',# e.g. "localhost:9000/"access_key='<your-minio-access-key>',secret_key='<your-minio-secret-key>')Usagemkdirslistdirexistsisdirtruncatermdirrmcpmvgetget_last_objectput_dataput_filemkdirs(self, path: str)Pyminio.mkdirswill create the given full path if not exists like linux'smkdir -p.This method must get a directory path or it will raise a ValueError.>>>pyminio_client.mkdirs('/foo/bar/baz/')>>>pyminio_client.mkdirs('/foo/bar/baz')ValueError/foo/bar/bazisnotavaliddirectorypath.mustbeabsoluteandendwith/listdir(self, path: str, files_only: bool = False, dirs_only: bool = False) -> Tuple[str]Pyminio.listdirwill return the directory's content as a tuple of directories and file names. Works like os'slistdir.This method must get a directory path or it will raise a ValueError.>>>pyminio_client.listdir('/foo/bar/baz/')('file_name_1','file_name_2','directory_name/')There is an option to use the files_only flag to get only files and dirs_only to get only directories from listdir.>>>pyminio_client.listdir('/foo/bar/baz/',files_only=True)('file_name_1','file_name_2')>>>pyminio_client.listdir('/foo/bar/baz/',dirs_only=True)('directory_name/',)exists(self, path: str) -> boolPyminio.existswill return a boolean that confirm rather this path exists or not in the server. Works like os'spath.exists./
├──foo
│└──bar
│└──baz
│├──file_name_1
│└──file_name_2>>>pyminio_client.exists('/foo/bar/baz/file_name_1')True>>>pyminio_client.exists('/foo/bar/baz/file_name_3')False>>>pyminio_client.exists('/all/path/wrong/')# not existing pathFalseisdir(self, path: str)Pyminio.isdirwill return True only if the given path exists and is a directory. Works likeos.path.isdir.>>>pyminio_client.isdir('/foo/bar/baz/file_name_1')# existed fileFalse>>>pyminio_client.isdir('/foo/bar/baz/directory_name/')# existed directoryTrue>>>pyminio_client.isdir('/all/path/wrong/but/directory/')# not existed directoryFalsetruncate(self) -> PyminioPyminio.truncatewill delete all minio's content from the root directory.>>>pyminio_client.truncate()rmdir(self, path: str, recursive: bool = False) -> PyminioPyminio.rmdirwill delete the specified directory. Works like linux'srmdir/rm (-r).It will raise aDirectoryNotEmptyErrorif given directory is not empty, except if the recursive flag is set and then it will delete given directory's path recursively.This method must get a directory path or it will raise a ValueError.>>>pyminio_client.rmdir('/foo/bar/baz/directory_name/')# empty directory>>>pyminio_client.rmdir('/foo/bar/')# non-empty directoryDirectoryNotEmptyError:cannotrecursivelydeletenon-emptydirectory>>>pyminio_client.rmdir('/foo/bar/',recursive=True)rm(self, path: str, recursive: bool = False) -> PyminioPyminio.rmworks likermdironly that it can delete files too. Works like linux'srm (-r).>>>pyminio_client.rm('/foo/bar/baz/file_name')cp(self, from_path: str, to_path: str, recursive: bool = False) -> PyminioPyminio.cpwill copy one file or directory to given destination. Works like linux'scp (-r).This method can only copy recursively when the recursive flag is True. If not, it will raise a ValueError.How will the copy accure? (all directories are copied recursively in this examples)src pathdst pathdst existsnew dstExplain/foo/bar/foo/baz---/foo/bazThe file's name will be copied from bar to baz as well./foo1/bar/foo2/True/foo/barThe file will be copied to '/foo2/bar'/foo/bar//foo/True/foo/The content of '/foo/bar/' will be copied to '/foo/'/foo1/bar//foo2/False/foo2/bar/'/foo1/bar/' will be copied recursively to '/foo2/bar/'/foo1/bar//foo2/baz------ValueError will be raised in attempting to copy directory in to a file>>>pyminio_client.cp('/foo/bar','/foo/baz')>>>pyminio_client.cp('/foo1/bar','/foo2/')>>>pyminio_client.cp('/foo/bar/','/foo/',recursive=True)>>>pyminio_client.cp('/foo1/bar/','/foo2/',recursive=True)>>>pyminio_client.cp('/foo1/bar/','/foo2/baz',recursive=True)ValueError:cannotactivatethismethodfromdirectorytoafile.mv(self, from_path: str, to_path: str, recursive: bool = False) -> PyminioPyminio.mvworks likecponly that it removes the source after the transfer has been completed. Works like linux'smv.This method can only move recursively when the recursive flag is True. If not, it will raise a ValueError.>>>pyminio_client.mv('/foo/bar/','/foo/baz/')get(self, path: str) -> ObjectDataPyminio.getreturn an object from given path. This object will be returned as apyminio.Fileobject or anpyminio.Folderobject, that both inherit frompyminio.ObjectData.This objects will contain metadata, their path and name.>>>pyminio_client.get('/foo/bar/baz')File(name='baz',full_path='/foo/bar/baz',metadata=AttrDict({'is_dir':False,'last_modified':time.struct_time(...),'size':...,'content-type':...}),data=...)get_last_object(self, path: str) -> FilePyminio.get_last_objectwill return the last modified object inside a given directory.This method must get a directory path or it will raise a ValueError.>>>pyminio_client.get_last_object('/foo/bar/')File(name='baz',full_path='/foo/bar/baz',metadata=AttrDict({'is_dir':False,'last_modified':time.struct_time(...),'size':...,'content-type':...}),data=...)put_data(self, path: str, data: bytes, metadata: Dict = None)Pyminio.put_datagets a path, data in bytes, and some metadata, and create an object inside the given path.>>>data=b'test'>>>metadata={'Pyminio-is':'Awesome'}>>>pyminio_client.put_data(path='/foo/bar/baz',data=data,metadata=metadata)put_file(self, file_path: str, to_path: str, metadata: Dict = None)Pyminio.put_fileworks likeput_dataonly that instead of data it gets a path to a file in you computer. Then it will copy this file to the given location.>>>metadata={'Pyminio-is':'Awesome'}>>>pyminio_client.put_file(to_path='/foo/bar/baz',file_path='/mnt/some_file',metadata=metadata)ContributeAll contributions are welcome:Read theissues, Fork theprojectand create a new Pull Request.Request a new feature creating aNew issuewith theenhancementtag.Find any kind of errors in the code and create aNew issuewith the details, or fork the project and do a Pull Request.Suggest a better or more pythonic way for existing examples.Work environmentAfter forking the project and installing the dependencies, (like specified in theinstallationsin part 2)
download theminio dockerand start an instance in your computer for development and testing.to run the tests run:pytestDon't forget to write tests, and to run all the tests before making a pull request.