agentfs


Nameagentfs JSON
Version 0.1.0 PyPI version JSON
download
home_pagehttps://github.com/AutonomousResearchGroup/agentfs
SummarySimple file management and serving for agents
upload_time2023-07-27 20:11:26
maintainer
docs_urlNone
authorMoon
requires_python
licenseMIT
keywords
VCS
bugtrack_url
requirements fastapi pydantic httpx
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
Simple file management and serving for agents


# Installation

```bash
pip install agentfs
```

## Quickstart

1. **Start the server**:
   You can start the server by using the `start_server()` function:

```python
from agentfs import start_server

start_server()
```

This will start the server at `http://localhost:8000`.

You can start the server with uvicorn like this:
```python
import os

if __name__ == "__main__":
    import uvicorn
    uvicorn.run("agentfs:start_server", host="0.0.0.0", port=int(os.getenv("PORT", 8000)))
```

2. **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.

```python
from agentfs import get_file

# Fetches the content of the file located at "./files/test.txt"
file_content = get_file("test.txt")
print(file_content)
```

3. **Save a file**:
   Similarly, you can save content to a file by sending a POST request to `/file/` endpoint, with JSON data containing the `path` and `content` parameters.

```python
from agentfs import add_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 Documentation

AgentFS provides the following public functions:

### `start_server(storage_path=None)`

Starts the FastAPI server. If a `storage_path` is provided, it sets the storage directory to the given path.

**Arguments**:

- `storage_path` (str, optional): The path to the storage directory.

**Returns**:

- None

**Example**:

```python
from agentfs import start_server

start_server("/my/storage/directory")
```

### `get_server()`

Returns the FastAPI application instance.

**Arguments**:

- None

**Returns**:

- FastAPI application instance.

**Example**:

```python
from agentfs import get_server

app = 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**:

- `True` if the path was successfully set, `False` otherwise.

**Example**:

```python
from agentfs import set_storage_path

set_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**:

- `True` if the file was successfully created.

**Example**:

```python
from agentfs import add_file

add_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**:

- `True` if the file was successfully removed.

**Example**:

```python
from agentfs import remove_file

remove_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**:

- `True` if the file was successfully updated.

**Example**:

```python
from agentfs import update_file

update_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**:

```python
from agentfs import list_files

files = 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**:

```python
from agentfs import get_file

content = get_file("test.txt")
```

# Contributions Welcome

If 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.


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/AutonomousResearchGroup/agentfs",
    "name": "agentfs",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Moon",
    "author_email": "shawmakesmagic@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/b0/aa/1dc25407f3e91298935675390ec6cfb9bf22c29a1cd9bc2246ad10aa424b/agentfs-0.1.0.tar.gz",
    "platform": null,
    "description": "\nSimple file management and serving for agents\n\n\n# Installation\n\n```bash\npip install agentfs\n```\n\n## Quickstart\n\n1. **Start the server**:\n   You can start the server by using the `start_server()` function:\n\n```python\nfrom agentfs import start_server\n\nstart_server()\n```\n\nThis will start the server at `http://localhost:8000`.\n\nYou can start the server with uvicorn like this:\n```python\nimport os\n\nif __name__ == \"__main__\":\n    import uvicorn\n    uvicorn.run(\"agentfs:start_server\", host=\"0.0.0.0\", port=int(os.getenv(\"PORT\", 8000)))\n```\n\n2. **Get a file**:\n   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.\n\n```python\nfrom agentfs import get_file\n\n# Fetches the content of the file located at \"./files/test.txt\"\nfile_content = get_file(\"test.txt\")\nprint(file_content)\n```\n\n3. **Save a file**:\n   Similarly, you can save content to a file by sending a POST request to `/file/` endpoint, with JSON data containing the `path` and `content` parameters.\n\n```python\nfrom agentfs import add_file\n\n# Creates a file named \"test.txt\" in the current storage directory\n# and writes \"Hello, world!\" to it.\nadd_file(\"test.txt\", \"Hello, world!\")\n```\n\n## API Documentation\n\nAgentFS provides the following public functions:\n\n### `start_server(storage_path=None)`\n\nStarts the FastAPI server. If a `storage_path` is provided, it sets the storage directory to the given path.\n\n**Arguments**:\n\n- `storage_path` (str, optional): The path to the storage directory.\n\n**Returns**:\n\n- None\n\n**Example**:\n\n```python\nfrom agentfs import start_server\n\nstart_server(\"/my/storage/directory\")\n```\n\n### `get_server()`\n\nReturns the FastAPI application instance.\n\n**Arguments**:\n\n- None\n\n**Returns**:\n\n- FastAPI application instance.\n\n**Example**:\n\n```python\nfrom agentfs import get_server\n\napp = get_server()\n```\n\n### `set_storage_path(new_path)`\n\nSets the storage directory to the provided path.\n\n**Arguments**:\n\n- `new_path` (str): The path to the new storage directory.\n\n**Returns**:\n\n- `True` if the path was successfully set, `False` otherwise.\n\n**Example**:\n\n```python\nfrom agentfs import set_storage_path\n\nset_storage_path(\"/my/storage/directory\")\n```\n\n### `add_file(path, content)`\n\nCreates a file at the specified path and writes the provided content to it.\n\n**Arguments**:\n\n- `path` (str): The path to the new file.\n- `content` (str): The content to be written to the file.\n\n**Returns**:\n\n- `True` if the file was successfully created.\n\n**Example**:\n\n```python\nfrom agentfs import add_file\n\nadd_file(\"test.txt\", \"Hello, world!\")\n```\n\n### `remove_file(path)`\n\nRemoves the file at the specified path.\n\n**Arguments**:\n\n- `path` (str): The path to the file to be removed.\n\n**Returns**:\n\n- `True` if the file was successfully removed.\n\n**Example**:\n\n```python\nfrom agentfs import remove_file\n\nremove_file(\"test.txt\")\n```\n\n### `update_file(path, content)`\n\nAppends the provided content to the file at the specified path.\n\n**Arguments**:\n\n- `path` (str): The path to the file to be updated.\n- `content` (str): The content to be appended to the file.\n\n**Returns**:\n\n- `True` if the file was successfully updated.\n\n**Example**:\n\n```python\nfrom agentfs import update_file\n\nupdate_file(\"test.txt\", \"New content\")\n```\n\n### `list_files(path='.')`\n\nLists all files in the specified directory.\n\n**Arguments**:\n\n- `path` (str, optional): The path to the directory. Defaults to `'.'` (current directory).\n\n**Returns**:\n\n- A list of file names in the specified directory.\n\n**Example**:\n\n```python\nfrom agentfs import list_files\n\nfiles = list_files()\n```\n\n### `get_file(path)`\n\nReturns the content of the file at the specified path.\n\n**Arguments**:\n\n- `path` (str): The path to the file.\n\n**Returns**:\n\n- A string containing the content of the file.\n\n**Example**:\n\n```python\nfrom agentfs import get_file\n\ncontent = get_file(\"test.txt\")\n```\n\n# Contributions Welcome\n\nIf 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.\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Simple file management and serving for agents",
    "version": "0.1.0",
    "project_urls": {
        "Homepage": "https://github.com/AutonomousResearchGroup/agentfs"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4cd9c81b47fd4ffbe80787d49f7f4f56eb6da5d4f00c24df04faf6295d81d2bc",
                "md5": "3e5f0be6c71c046a10f809fd5a76a816",
                "sha256": "6f55a11c258c5e75c42d4c19551835b426304aee95375cc7fccfadbdcb32fd2f"
            },
            "downloads": -1,
            "filename": "agentfs-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3e5f0be6c71c046a10f809fd5a76a816",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 5223,
            "upload_time": "2023-07-27T20:11:25",
            "upload_time_iso_8601": "2023-07-27T20:11:25.295041Z",
            "url": "https://files.pythonhosted.org/packages/4c/d9/c81b47fd4ffbe80787d49f7f4f56eb6da5d4f00c24df04faf6295d81d2bc/agentfs-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b0aa1dc25407f3e91298935675390ec6cfb9bf22c29a1cd9bc2246ad10aa424b",
                "md5": "d0ba15a5818276e3508fe43a926479ee",
                "sha256": "a1168d1fcef540c7798d89ba35a446e37e9e677eadc87d4bd1ae9b3f91fe8527"
            },
            "downloads": -1,
            "filename": "agentfs-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "d0ba15a5818276e3508fe43a926479ee",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 4779,
            "upload_time": "2023-07-27T20:11:26",
            "upload_time_iso_8601": "2023-07-27T20:11:26.956505Z",
            "url": "https://files.pythonhosted.org/packages/b0/aa/1dc25407f3e91298935675390ec6cfb9bf22c29a1cd9bc2246ad10aa424b/agentfs-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-07-27 20:11:26",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "AutonomousResearchGroup",
    "github_project": "agentfs",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "fastapi",
            "specs": []
        },
        {
            "name": "pydantic",
            "specs": []
        },
        {
            "name": "httpx",
            "specs": []
        }
    ],
    "lcname": "agentfs"
}
        
Elapsed time: 0.10412s