You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
109 lines
2.7 KiB
109 lines
2.7 KiB
# arango |
|
|
|
A simple Python wrapper for connecting to and interacting with ArangoDB. |
|
|
|
## Installation |
|
|
|
Install dependencies: |
|
|
|
```bash |
|
pip install -r requirements.txt |
|
``` |
|
|
|
You also need to install `env_manager` to help set up environment variables for ArangoDB: |
|
|
|
```bash |
|
pip install git+https://github.com/lasseedfast/env_manager.git |
|
``` |
|
|
|
## Usage |
|
|
|
Environment variables: |
|
|
|
- `ARANGO_HOST` |
|
- `ARANGO_DB` |
|
- `ARANGO_USERNAME` |
|
- `ARANGO_PWD` |
|
|
|
The package will use `env_manager` to set them automatically (first time you may need to provide a password). |
|
|
|
Example: |
|
|
|
```python |
|
from _arango import arango |
|
|
|
results = arango.execute_aql("FOR doc IN my_collection RETURN doc") |
|
``` |
|
|
|
## AdminArango: Database and User Administration |
|
|
|
The `AdminArango` class provides administrative functionality for ArangoDB, such as creating and deleting databases, managing users, and setting permissions. It connects to the `_system` database for these operations. |
|
|
|
Example usage: |
|
|
|
```python |
|
from _arango.arango import AdminArango |
|
|
|
admin = AdminArango() |
|
admin.create_database("mydb") |
|
admin.create_user("username", password="secret") |
|
admin.set_user_permission("username", "rw", "mydb") |
|
admin.list_databases() |
|
admin.delete_user("username") |
|
admin.delete_database("mydb") |
|
``` |
|
|
|
Features: |
|
- Create and delete databases |
|
- List all databases |
|
- Create and delete users |
|
- Set user permissions for databases and collections |
|
|
|
|
|
## Interactive Admin Terminal Guide |
|
|
|
You can use the built-in terminal guide to perform common admin tasks interactively: |
|
|
|
- **Create a database** |
|
- **Create a user and set permissions** |
|
|
|
To start the guide, you have two options: |
|
|
|
**Option 1: Run from Python code** |
|
```python |
|
from _arango import admin |
|
|
|
admin() |
|
``` |
|
|
|
**Option 2: Run directly from the terminal** |
|
```bash |
|
python -m _arango.arango admin |
|
``` |
|
Or, if your Python path is set up, you can also run: |
|
```bash |
|
python -m _arango.arango |
|
``` |
|
This will start the guide if you add logic to handle command-line arguments (see below). |
|
|
|
Permission options are explained in the guide: |
|
- `rw` – read and write access |
|
- `ro` – read-only access |
|
- `none` – no access |
|
|
|
For more details on permissions, see: [ArangoDB User Permissions](https://docs.python-arango.com/en/main/specs.html#user-permissions) |
|
|
|
|
|
## Using as a Base for Your Own Project |
|
|
|
If you want to use this package as a starting point for your own ArangoDB utilities, you can clone the repository: |
|
|
|
```bash |
|
git clone https://git.edfast.se/lasse/arango.git |
|
``` |
|
|
|
You can then add your own methods and modify the code as needed. If you do not plan to sync changes back to the original repository, consider to remove or change the remote origin to avoid accidentally pushing changes to the original repo: |
|
```bash |
|
git remote remove origin |
|
``` |
|
|
|
|