{"id":21197619,"url":"https://github.com/jason-cky/directus-sdk-python","last_synced_at":"2025-10-30T10:11:10.753Z","repository":{"id":122091207,"uuid":"483942333","full_name":"Jason-CKY/directus-sdk-python","owner":"Jason-CKY","description":"Python SDK for directus client with convenience functions","archived":false,"fork":false,"pushed_at":"2022-05-03T10:07:54.000Z","size":35,"stargazers_count":14,"open_issues_count":0,"forks_count":6,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-10T10:09:43.014Z","etag":null,"topics":["directus","python","sdk-python"],"latest_commit_sha":null,"homepage":"","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/Jason-CKY.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-04-21T07:02:38.000Z","updated_at":"2024-09-30T20:02:07.000Z","dependencies_parsed_at":null,"dependency_job_id":"24a86cf1-c102-4c00-a2be-30162c5bd7b5","html_url":"https://github.com/Jason-CKY/directus-sdk-python","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Jason-CKY/directus-sdk-python","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jason-CKY%2Fdirectus-sdk-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jason-CKY%2Fdirectus-sdk-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jason-CKY%2Fdirectus-sdk-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jason-CKY%2Fdirectus-sdk-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Jason-CKY","download_url":"https://codeload.github.com/Jason-CKY/directus-sdk-python/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jason-CKY%2Fdirectus-sdk-python/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281786831,"owners_count":26561426,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-30T02:00:06.501Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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","sdk-python"],"created_at":"2024-11-20T19:45:43.258Z","updated_at":"2025-10-30T10:11:10.749Z","avatar_url":"https://github.com/Jason-CKY.png","language":"Python","readme":"\u003ch1\u003e\n    \u003cimg src=\"assets/logo.jpg\", width=\"40\", alt=\"Directus Logo\"\u003e Directus Python SDK\n\u003c/h1\u003e\n\n[![Tests](https://github.com/Jason-CKY/directus-sdk-python/actions/workflows/test.yaml/badge.svg)](https://github.com/Jason-CKY/directus-sdk-python/actions/workflows/test.yaml) ![coverage](https://raw.githubusercontent.com/Jason-CKY/directus-sdk-python/badges/main/coverage-badge.svg)\n\n## Requirements\n\n- Python 3.6+\n\n## Installation\n\n```bash\npip install -e .\n```\n\n## Usage\n\n### Initializa directus client\n\n```python\nfrom directus.clients import DirectusClient_V9\n\n# Create a directus client connection with user static token\nclient = DirectusClient_V9(url=\"http://localhost:8055\", token=\"admin-token\")\n\n# Or create a directus client connection with email and password\nclient = DirectusClient_V9(url=\"http://localhost:8055\", email=\"user@example.com\", password=\"password\")\n```\n\n### Logging in and out of the client\n\n```python\nclient = DirectusClient_V9(url=\"http://localhost:8055\", email=\"user@example.com\", password=\"password\")\n\n# Log out and use static token instead\nclient.logout()\nclient.static_token = \"admin-token\"\nclient.login(email=\"user2@example.com\", password=\"password2\")\n```\n\n### Generic API requests\n\nThe directus client automatically handles the injection of access token so any [directus API requests](https://docs.directus.io/reference/introduction/) can be simplified like so:\n\n```python\n# GET request\ncollection = client.get(f\"/collections/{collection_name}\")\nitem = client.get(f\"/items/{collection_name}/1\")\n\n# POST request\nitems = [\n    {\n        \"name\": \"item1\"\n    },\n    {\n        \"name\": \"item2\"\n    }\n]\n\nclient.post(f\"/items/{collection_name}\", json=items)\n\n# PATCH request\nclient.patch(f\"/items/{collection_name}/1\", json={\n    \"name\": \"updated item1\"\n})\n\n# DELETE request\nclient.delete(f\"/items/{collection_name}/1\")\n```\n\n#### Bulk Insert\n\n\u003e **Params:** collection_name: str, items: list\n\n```python\nclient.bulk_insert(collection_name=\"test-collection\",\n                    items=[{\"Title\": \"test\"}, {\"Title\": \"test2\"}])\n```\n\n#### Duplicate Collection\n\n\u003e **Params:** collection_name: str, duplicate_collection_name: str\n\n```python\nclient.duplicate_collection(collection_name=\"test-collection\", duplicate_collection_name=\"test_duplication_collection\")\n```\n\n#### Checks if collection exists\n\n\u003e **Params** collection_name: str, items: list\n\n```python\nif client.collection_exists(\"test\"):\n    print(\"test collection exists!\")\n```\n\n#### Delete all items from a collection\n\n\u003e **Params:** collection_name: str\n\n```python\nclient.delete_all_items(\"test\")\n```\n\n#### Get collection primary key\n\n\u003e **Params:** collection_name: str\n\n```python\npk_field = client.get_pk_field(\"brands\")\n```\n\n#### Get all user-created collection names\n\n\u003e **Params:**\n\n```python\nprint(\"Listing all user-created collections on directus...\")\nfor name in client.get_all_user_created_collection_names():\n    print(name)\n```\n\n#### Get all field names of a given collection\n\n\u003e **Params:** collection_name: str\n\n```python\nprint(\"Listing all fields in test collection...\")\nfor field in client.get_all_fields(\"test\"):\n    print(json.dumps(field, indent=4))\n```\n\n#### Get all foreign key fields in directus collection\n\n\u003e **Params:** collection_name: str\n\n```python\nprint(\"Listing all foreign key fields in test collection...\")\nfor field in client.get_all_fk_fields(\"brands\"):\n    print(json.dumps(field, indent=4))\n```\n\n#### Get all relations in directus collection\n\n\u003e **Params:** collection_name: str\n\n```python\nimport json\nprint(\"Listing all relations in test collection...\")\nfor field in client.get_relations(\"test\"):\n    print(json.dumps(field, indent=4))\n```\n\n#### Create relations\n\n\u003e **Params:** relation: dict\n\n```python\nclient.post_relation({\n    \"collection\": \"books\",\n    \"field\": \"author\",\n    \"related_collection\": \"authors\"\n})\n```\n\n\n## TODOs:\n\n* debug test cases\n* add proper pytest","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjason-cky%2Fdirectus-sdk-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjason-cky%2Fdirectus-sdk-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjason-cky%2Fdirectus-sdk-python/lists"}