This codebase is a work-in-progress. The repo is here as a placeholder for anyone interested in contributing to the software development kit. Pull-requests and contributions are welcome!
- Python 3.7+
Simply install the package from the root directory with:
pip install .
from directus import DirectusClient
# Creates a Directus anonymous client object
client = DirectusClient(url="http://localhost:8080", project="directus")
# Create a Directus client from a user (generates access token)
client = DirectusClient(url="http://localhost:8080", project="directus", email="[email protected]", password="password")
Params: offset (int), single (bool), meta (List of str)
collections, metadata = client.get_collections_list()
Params: collection (required str), meta (List of str)
collection, metadata = client.get_collection(collection="sports")
Params: new_collection (required Collection obj), meta (List of str)
# First create your Collection object
from directus.models import Collection
new_collection = Collection(**{
"collection": "sports",
"fields": [
{
"field": "id",
"type": "integer",
"datatype": "int",
"length": 11,
"interface": "numeric",
"primary_key": True
}
]
})
# Then, create the collection in the API
created_collection, metadata = client.create_collection(new_collection=new_collection)
Params: collection (required str), data (required dict), meta (List of str)
updated_collection, metadata = client.update_collection(collection="sports", data={"note":"Hello World!"})
Params: collection (required str)
collection_is_deleted = client.delete_collection(collection="sports")
Params: collection (required str), fields (List of str), page (int), limit (int), offset (int), sort (List of str), single (bool), status (str), q (str), meta (List of str)
By default, if a page is specified, offset will be ignored
sports, metadata = client.get_items_list(collection="sports")
Params: collection (required str), fields (List of str), sort (List of str), status (str), q (str), meta (List of str)
all_sports, metadata = client.get_all_items_list(collection="sports")
Params: collection (required str), id (required int), fields (List of str), meta (List of str)
sport, metadata = client.get_item(collection="sports", id=1)
Params: collection (required str), item (required dict), meta (List of str)
created_sport, metadata = client.create_item(collection="sports", item=item_data)
Params: collection (required str), id (required int), data (required dict), fields (List of str), meta (List of str)
updated_sport, metadata = client.update_item(collection="sports", id=1, data=item_data_to_update)
Params: collection (required str), id (required int)
sport_deleted = client.delete_item(collection="sports", id=1)
Params: collection (required str), id (required int), fields (List of str), limit (int), offset (int), page (int), sort (List of str), single (bool), filter (dict), q (str), meta (List of str)
By default, if a page is specified, offset will be ignored
sport_revisions = client.get_item_revisions_list(collection="sports", id=1)
Params: collection (required str), id (required int), offset (required int), fields (List of str), meta (List of str)
sport_revision = client.get_item_revision(collection="sports", id=1, offset= 2)
Params: collection (required str), id (required int), revision (int), fields (List of str), meta (List of str)
reverted_sport = client.revert_item_revision(collection="sports", id=1, revision=2)
Params: fields (List of str), page (int), limit (int), offset (int), sort (List of str), filter (dict), single (bool), status (str), q (str), meta (List of str)
files, metadata = client.get_files_list()
Params: id (required int), fields (List of str), meta (List of str)
file, metadata = client.get_file(id=1)
Params: data (required str), filename_download (str), title (str), description (str), location (str), tags (str), metadata (str), meta (List of str)
file, metadata = client.create_file(data="https://picsum.photos/200/300")
Params: send_to (required str), subject (required str), body (required str), type (str), data (dict)
client.send_email(send_to="[email protected]", subject="Hello world!", body="This is my message to you")
Simply install the project from scratch with the following command:
make install
You can lint or format the code using the following commands:
make lint
make format
In order to run tests, we rely on docker and docker-compose for setting up a Directus API.
Start the docker environment:
docker-compose up -d
Usually wait few seconds before the docker environment is ready to accept requests and you can run tests:
make test
For more details, please see the Makefile
file.