Package: agentfs
Simple file management and serving for agentsInstallationpipinstallagentfsQuickstartStart the server:
You can start the server by using thestart_server()function:fromagentfsimportstart_serverstart_server()This will start the server athttp://localhost:8000.You can start the server with uvicorn like this:importosif__name__=="__main__":importuvicornuvicorn.run("agentfs:start_server",host="0.0.0.0",port=int(os.getenv("PORT",8000)))Get a file:
Once the server is up and running, you can retrieve file content by sending a GET request to/file/{path}endpoint, where{path}is the path to the file relative to the server's current storage directory.fromagentfsimportget_file# Fetches the content of the file located at "./files/test.txt"file_content=get_file("test.txt")print(file_content)Save a file:
Similarly, you can save content to a file by sending a POST request to/file/endpoint, with JSON data containing thepathandcontentparameters.fromagentfsimportadd_file# Creates a file named "test.txt" in the current storage directory# and writes "Hello, world!" to it.add_file("test.txt","Hello, world!")API DocumentationAgentFS provides the following public functions:start_server(storage_path=None)Starts the FastAPI server. If astorage_pathis provided, it sets the storage directory to the given path.Arguments:storage_path(str, optional): The path to the storage directory.Returns:NoneExample:fromagentfsimportstart_serverstart_server("/my/storage/directory")get_server()Returns the FastAPI application instance.Arguments:NoneReturns:FastAPI application instance.Example:fromagentfsimportget_serverapp=get_server()set_storage_path(new_path)Sets the storage directory to the provided path.Arguments:new_path(str): The path to the new storage directory.Returns:Trueif the path was successfully set,Falseotherwise.Example:fromagentfsimportset_storage_pathset_storage_path("/my/storage/directory")add_file(path, content)Creates a file at the specified path and writes the provided content to it.Arguments:path(str): The path to the new file.content(str): The content to be written to the file.Returns:Trueif the file was successfully created.Example:fromagentfsimportadd_fileadd_file("test.txt","Hello, world!")remove_file(path)Removes the file at the specified path.Arguments:path(str): The path to the file to be removed.Returns:Trueif the file was successfully removed.Example:fromagentfsimportremove_fileremove_file("test.txt")update_file(path, content)Appends the provided content to the file at the specified path.Arguments:path(str): The path to the file to be updated.content(str): The content to be appended to the file.Returns:Trueif the file was successfully updated.Example:fromagentfsimportupdate_fileupdate_file("test.txt","New content")list_files(path='.')Lists all files in the specified directory.Arguments:path(str, optional): The path to the directory. Defaults to'.'(current directory).Returns:A list of file names in the specified directory.Example:fromagentfsimportlist_filesfiles=list_files()get_file(path)Returns the content of the file at the specified path.Arguments:path(str): The path to the file.Returns:A string containing the content of the file.Example:fromagentfsimportget_filecontent=get_file("test.txt")Contributions WelcomeIf you like this library and want to contribute in any way, please feel free to submit a PR and I will review it. Please note that the goal here is simplicity and accesibility, using common language and few dependencies.