- Python 3.6+
pip install -e .from directus.clients import DirectusClient_V9
# Create a directus client connection with user static token
client = DirectusClient_V9(url="http://localhost:8055", token="admin-token")
# Or create a directus client connection with email and password
client = DirectusClient_V9(url="http://localhost:8055", email="[email protected]", password="password")client = DirectusClient_V9(url="http://localhost:8055", email="[email protected]", password="password")
# Log out and use static token instead
client.logout()
client.static_token = "admin-token"
client.login(email="[email protected]", password="password2")The directus client automatically handles the injection of access token so any directus API requests can be simplified like so:
# GET request
collection = client.get(f"/collections/{collection_name}")
item = client.get(f"/items/{collection_name}/1")
# POST request
items = [
    {
        "name": "item1"
    },
    {
        "name": "item2"
    }
]
client.post(f"/items/{collection_name}", json=items)
# PATCH request
client.patch(f"/items/{collection_name}/1", json={
    "name": "updated item1"
})
# DELETE request
client.delete(f"/items/{collection_name}/1")Params: collection_name: str, items: list
client.bulk_insert(collection_name="test-collection",
                    items=[{"Title": "test"}, {"Title": "test2"}])Params: collection_name: str, duplicate_collection_name: str
client.duplicate_collection(collection_name="test-collection", duplicate_collection_name="test_duplication_collection")Params collection_name: str, items: list
if client.collection_exists("test"):
    print("test collection exists!")Params: collection_name: str
client.delete_all_items("test")Params: collection_name: str
pk_field = client.get_pk_field("brands")Params:
print("Listing all user-created collections on directus...")
for name in client.get_all_user_created_collection_names():
    print(name)Params: collection_name: str
print("Listing all fields in test collection...")
for field in client.get_all_fields("test"):
    print(json.dumps(field, indent=4))Params: collection_name: str
print("Listing all foreign key fields in test collection...")
for field in client.get_all_fk_fields("brands"):
    print(json.dumps(field, indent=4))Params: collection_name: str
import json
print("Listing all relations in test collection...")
for field in client.get_relations("test"):
    print(json.dumps(field, indent=4))Params: relation: dict
client.post_relation({
    "collection": "books",
    "field": "author",
    "related_collection": "authors"
})- debug test cases
- add proper pytest
