{"id":37076130,"url":"https://github.com/reise69/directus-py-sdk","last_synced_at":"2026-01-14T08:57:34.801Z","repository":{"id":232190526,"uuid":"783719545","full_name":"reise69/directus-py-sdk","owner":"reise69","description":"A Python SDK for Directus","archived":false,"fork":false,"pushed_at":"2024-11-09T11:26:37.000Z","size":22,"stargazers_count":22,"open_issues_count":3,"forks_count":6,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-05T20:02:38.201Z","etag":null,"topics":["directus","python"],"latest_commit_sha":null,"homepage":"https://www.refbax.com","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/reise69.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2024-04-08T12:46:47.000Z","updated_at":"2025-09-17T22:40:52.000Z","dependencies_parsed_at":"2024-04-08T13:43:15.013Z","dependency_job_id":null,"html_url":"https://github.com/reise69/directus-py-sdk","commit_stats":null,"previous_names":["reise69/directus-py-sdk"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/reise69/directus-py-sdk","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reise69%2Fdirectus-py-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reise69%2Fdirectus-py-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reise69%2Fdirectus-py-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reise69%2Fdirectus-py-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/reise69","download_url":"https://codeload.github.com/reise69/directus-py-sdk/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reise69%2Fdirectus-py-sdk/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28414723,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T08:38:59.149Z","status":"ssl_error","status_checked_at":"2026-01-14T08:38:43.588Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["directus","python"],"created_at":"2026-01-14T08:57:34.110Z","updated_at":"2026-01-14T08:57:34.797Z","avatar_url":"https://github.com/reise69.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Directus SDK for Python\n\n[![PyPI version](https://badge.fury.io/py/directus-sdk-py.svg)](https://badge.fury.io/py/directus-sdk-py)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![Python Version](https://img.shields.io/pypi/pyversions/directus-sdk-py.svg)](https://pypi.org/project/directus-sdk-py/)\n\nA Python SDK for interacting with Directus, an open-source headless CMS and API platform.\n\n## About Directus\n\n[Directus](https://directus.io/) is a powerful and flexible open-source headless CMS and API platform. It provides a\nuser-friendly interface for managing content and a robust API for integrating with other applications. Directus allows\nyou to create and customize your data models, manage users and permissions, and easily expose your data through a\nRESTful API.\n\n## About the library\n\nThis library provides a Python SDK for interacting with Directus. You can use it to perform various operations such as\nmanaging users, files, collections, and items. The SDK simplifies the process of interacting with the Directus API by\nproviding a set of methods that you can use to perform common tasks.\n\n## New features (1.1.0)\n\n- Enhanced authentication handling with token expiration support\n- New `me()` method to get current user information\n- Improved file handling with automatic file type detection\n- New `DirectusQueryBuilder` for constructing complex queries\n- SQL to Directus query converter (`SQLToDirectusConverter`)\n- Better error handling and response processing\n- Enhanced image transformation capabilities\n- Improved URL handling and cleaning\n\n## Installation\n\nYou can install the Directus Python SDK using pip:\n\n```bash\npip install directus-sdk-py\n```\n\n## Usage\n\nHere are some examples of how to use the Directus Python SDK:\n\n### Initialize the Client\n\n```python\nfrom directus_sdk_py import DirectusClient\n\nclient = DirectusClient(url='https://your-directus-instance.com', token='your_access_token')\n```\n\n### Authentication with email and password if needed\n\n```python\n# Login with email and password\nclient.login(email='user@example.com', password='password')\n\n# Get current user information\nme = client.me()\n\n# Refresh token\nclient.refresh()\n\n# Logout\nclient.logout()\n```\n\n### Users Management\n\n```python\n# Get all users\nusers = client.get_users()\n\n# Create a new user\nuser_data = {\n    'first_name': 'John',\n    'last_name': 'Doe',\n    'email': 'john@example.com',\n    'password': 'password'\n}\nnew_user = client.create_user(user_data)\n\n# Update a user\nupdated_user = client.update_user(user_id='user_id', user_data={'first_name': 'Updated Name'})\n\n# Delete a user\nclient.delete_user(user_id='user_id')\n```\n\n### Files Management\n\n```python\n# Get all files\nfiles = client.get_files()\n\n# Search files with a filter\nrequest = {\n    \"query\": {\n        \"filter\": {\n            \"title\": {\n                \"_icontains\": \"my search request\" # Search for files with \"my search request\" in the title\n            }\n        }\n    }\n}\nitems = client.get_files(request)\n\n\n# Suppose you get an item and it's a photo, you can get the URL of the photo with the following code\nphoto_url = client.get_file_url(items[0]['id'])\n\n# It's possible to transform or add some display options to the photo URL\ndisplay = {\n    \"quality\": 95, # Quality of the image\n}\ntransform = [\n    [\"blur\", 10], # Blur the image\n    [\"tint\", \"rgb(255, 0, 0)\"] # Tint the image in red\n]\n\nphoto_url = client.get_file_url(items[0]['id'], display=display, transform=transform)\n\n# Download the file on the disk\nclient.download_photo(items[0]['id'], 'path/to/download.jpg', display=display, transform=transform)\n\n\n# Download a file other than a photo\nclient.download_file(items[0]['id'], 'path/to/download.jpg')\n\n\n# Upload a file\ndata = {\n    \"title\": \"Readme\",\n    \"description\": \"Readme file\",\n    \"tags\": ['readme', 'file'],\n}\nfile = client.upload_file(\"readme.md\", data)\n\n# Delete a file\nclient.delete_file(file_id='file_id')\n```\n\nInformation about filter requests can be found in\nthe [Directus API documentation](https://docs.directus.io/reference/filter-rules.html)\n\n### Collection and Item Management\n\n```python\n# Get a collection\ncollection = client.get_collection(collection_name='your_collection')\n\n# List all items and filter the results\ncollection = \"my_collection\"\nrequest = {\n    \"query\": {\n        # More information about filter requests can be found in the Directus API documentation (https://docs.directus.io/reference/filter-rules.html)\n        \"filter\": {\n            \"col_name\": {\n                \"_icontains\": \"inverness\" # Search inverness in the col_name column\n            }\n        }\n    }\n}\nitems = client.get_items(collection, request)\n\n\n# Get an item from a collection\nitem = client.get_item(collection_name='your_collection', item_id='item_id')\n\n# Create a new item in a collection\nitem_data = {\n    'title': 'New Item',\n    'description': 'This is a new item'\n}\nnew_item = client.create_item(collection_name='your_collection', item_data=item_data)\n\n# Update an item in a collection\nupdated_item = client.update_item(collection_name='your_collection', item_id='item_id',\n                                  item_data={'title': 'Updated Title'})\n\n# Delete an item from a collection\nclient.delete_item(collection_name='your_collection', item_id='item_id')\n```\n\n## Using DirectusQueryBuilder\n\nThe new DirectusQueryBuilder provides a fluent interface for constructing complex queries:\n\n```python\nfrom directus_sdk_py import DirectusQueryBuilder, DOp\n\n# Create a builder instance\nbuilder = DirectusQueryBuilder()\n\n# Build a complex query\nquery = (builder\n    .field(\"status\", DOp.EQUALS, \"published\")\n    .or_condition([\n        {\"author\": {DOp.EQUALS: \"john\"}},\n        {\"category\": {DOp.IN: [\"news\", \"tech\"]}}\n    ])\n    .sort(\"date_created\", \"-title\")\n    .limit(10)\n    .offset(0)\n    .build())\n\n# Use the query\nitems = client.get_items(\"articles\", query)\n```\n\n## SQL to Directus Query Converter\n\nFor those like me, like to use SQL instead of Directus query language, you can use the `SQLToDirectusConverter` to convert your SQL queries to Directus query format:\n\n```python\nfrom directus_sdk_py import SQLToDirectusConverter\n\nconverter = SQLToDirectusConverter()\n\nsql_query = \"\"\"\nSELECT * FROM articles\nWHERE status = 'published'\nAND (author = 'john' OR category IN ('news', 'tech'))\nORDER BY date_created ASC, title DESC\n\"\"\"\n\ndirectus_query = converter.convert(sql_query)\nitems = client.get_items(\"articles\", directus_query)\n\n```\n\n## Contributing\n\nContributions are welcome! If you find any issues or have suggestions for improvements, please:\n\n- Fork the repository\n- Create a new branch for your feature\n- Submit a pull request\n\n## License\n\nThis project is licensed under the MIT License.\n\n## Acknowledgements\n\nThis library was inspired by the [directus-sdk-python](https://github.com/Jason-CKY/directus-sdk-python) project, which\nis also released under the MIT License. Special thanks to the contributors of that project for their work.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freise69%2Fdirectus-py-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Freise69%2Fdirectus-py-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freise69%2Fdirectus-py-sdk/lists"}