Skip to main content

A bunch of scripts that abstracts the Directus-REST-Api for faster development.

Project description

Directus-Python-Client

This library aims to provide a simple and easy to use interface to the Directus API. It is written in Python and uses the requests library.

Motivation

Working with APIs can sometimes be a bit cumbersome. If you are not careful, boilerplates can quickly lead to code duplication. Most of the time they come from similar workflows. Like authentication, request header configuration or just the execution of the request itself.

Documentation

Authentication

from directus_api import DirectusApi

# Authentication
directus_api = DirectusApi(username="username", password="password", endpoint="https://directus.example.com")

Items

Retrieve Items:

...

# Get all items from a collection
items = directus_api.get_items(collection="collection_name")

# Get only 42 items from a collection
items = directus_api.get_items(collection="collection_name", limit=42)

# Filter items with (match_id equals 'wzi6xmt37') only 42 items from a collection
items = directus_api.get_items(collection="collection_name", limit=42,
                               filter_dict={'match_id': {'_eq': 'wzi6xmt37'}})

print(items)

Create Items:

...

# Create a single item or multiple items
item = directus_api.create_items(collection="collection_name", data=[{"title": "My new item"}])

Update Items:

...

# Update a single item or multiple items. Primary key (here 'id') is required.
item = directus_api.update_items(collection="collection_name", data=[{"title": "My updated item", "id": 1}])

Delete Items:

...
# Delete a single item by id from a collection
item = directus_api.delete_item_by_id(collection="collection_name", id=1)

# Delete all items from a collection
item = directus_api.delete_all_items_from_collection(collection="collection_name")

...

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

directus-python-client-0.1.1.tar.gz (3.7 kB view hashes)

Uploaded Source

Built Distribution

directus_python_client-0.1.1-py3-none-any.whl (4.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page