Simple file management and serving for agents
[](https://github.com/AutonomousResearchGroup/agentcomlink/actions/workflows/test.yml)
[](https://badge.fury.io/py/agentcomlink)
# Installation
```bash
pip install agentcomlink
```
## Quickstart
1. **Start the server**:
You can start the server with uvicorn like this:
```python
import os
if __name__ == "__main__":
import uvicorn
uvicorn.run("agentcomlink:start_server", host="0.0.0.0", port=int(os.getenv("PORT", 8000)))
```
This will start the server at `http://localhost: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 agentcomlink 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 agentcomlink 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 agentcomlink import start_server
start_server("/my/storage/directory")
```
### `get_server()`
Returns the FastAPI application instance.
**Arguments**:
- None
**Returns**:
- FastAPI application instance.
**Example**:
```python
from agentcomlink 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 agentcomlink 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 agentcomlink 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 agentcomlink 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 agentcomlink 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 agentcomlink import list_files
files = list_files()
```
### `list_files_formatted(path='.')`
Lists all files in the specified directory as a formatted string. Convenient!
**Arguments**:
- `path` (str, optional): The path to the directory. Defaults to `'.'` (current directory).
**Returns**:
- A string containing a list of file names in the specified directory.
**Example**:
```python
from agentcomlink 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 agentcomlink 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/agentcomlink",
"name": "agentcomlink",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "",
"author": "Moon",
"author_email": "shawmakesmagic@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/fc/fb/7a56a1698dcf29af556abdcd8754a5fc7071b79ddd881ccfab0049e5888d/agentcomlink-0.1.10.tar.gz",
"platform": null,
"description": "\nSimple file management and serving for agents\n\n\n[](https://github.com/AutonomousResearchGroup/agentcomlink/actions/workflows/test.yml)\n[](https://badge.fury.io/py/agentcomlink)\n\n# Installation\n\n```bash\npip install agentcomlink\n```\n\n## Quickstart\n\n1. **Start the server**:\n You can start the server with uvicorn like this:\n\n```python\nimport os\n\nif __name__ == \"__main__\":\n import uvicorn\n uvicorn.run(\"agentcomlink:start_server\", host=\"0.0.0.0\", port=int(os.getenv(\"PORT\", 8000)))\n```\n\nThis will start the server at `http://localhost:8000`.\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 agentcomlink 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 agentcomlink 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 agentcomlink 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 agentcomlink 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 agentcomlink 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 agentcomlink 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 agentcomlink 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 agentcomlink 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 agentcomlink import list_files\n\nfiles = list_files()\n```\n\n### `list_files_formatted(path='.')`\n\nLists all files in the specified directory as a formatted string. Convenient!\n\n**Arguments**:\n\n- `path` (str, optional): The path to the directory. Defaults to `'.'` (current directory).\n\n**Returns**:\n\n- A string containing a list of file names in the specified directory.\n\n**Example**:\n\n```python\nfrom agentcomlink 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 agentcomlink 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 chat, debug and file management panel for agents",
"version": "0.1.10",
"project_urls": {
"Homepage": "https://github.com/AutonomousResearchGroup/agentcomlink"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "32e769899799675c18efc7052f8c8469f60ebc6a1abc67bed73260337c42ff1c",
"md5": "d168b9579ea021df6d2d1632637e7ce7",
"sha256": "13e59f49e13d328095fa172a2488abdc81dac2ee3faa30444383eefc4ae6f028"
},
"downloads": -1,
"filename": "agentcomlink-0.1.10-py3-none-any.whl",
"has_sig": false,
"md5_digest": "d168b9579ea021df6d2d1632637e7ce7",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 8829,
"upload_time": "2023-08-01T06:17:25",
"upload_time_iso_8601": "2023-08-01T06:17:25.113556Z",
"url": "https://files.pythonhosted.org/packages/32/e7/69899799675c18efc7052f8c8469f60ebc6a1abc67bed73260337c42ff1c/agentcomlink-0.1.10-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "fcfb7a56a1698dcf29af556abdcd8754a5fc7071b79ddd881ccfab0049e5888d",
"md5": "50646322d2a80d24d14a43b54ee44caf",
"sha256": "7a6bc23609fba42188706ee8852f425352c3d7ce4056c14ad81cb348bac32a71"
},
"downloads": -1,
"filename": "agentcomlink-0.1.10.tar.gz",
"has_sig": false,
"md5_digest": "50646322d2a80d24d14a43b54ee44caf",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 9394,
"upload_time": "2023-08-01T06:17:26",
"upload_time_iso_8601": "2023-08-01T06:17:26.619624Z",
"url": "https://files.pythonhosted.org/packages/fc/fb/7a56a1698dcf29af556abdcd8754a5fc7071b79ddd881ccfab0049e5888d/agentcomlink-0.1.10.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-08-01 06:17:26",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "AutonomousResearchGroup",
"github_project": "agentcomlink",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "agentcomlink"
}