{"id":21476626,"url":"https://github.com/dnlbauer/django-signposting","last_synced_at":"2025-07-15T10:32:28.971Z","repository":{"id":263449037,"uuid":"843116567","full_name":"dnlbauer/django-signposting","owner":"dnlbauer","description":"A Django middleware that adds FAIR signposting headers to HTTP responses, making your web application more FAIR.","archived":false,"fork":false,"pushed_at":"2024-11-18T16:25:02.000Z","size":43,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-18T16:58:50.770Z","etag":null,"topics":["django","fair","fair-data","links","linkset","rfc8288","signposting"],"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/dnlbauer.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}},"created_at":"2024-08-15T20:18:41.000Z","updated_at":"2024-11-18T16:23:57.000Z","dependencies_parsed_at":"2024-11-18T16:59:04.736Z","dependency_job_id":"e855e276-dd1b-4603-85d2-7281da9a5d00","html_url":"https://github.com/dnlbauer/django-signposting","commit_stats":null,"previous_names":["dnlbauer/django-signposting"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dnlbauer%2Fdjango-signposting","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dnlbauer%2Fdjango-signposting/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dnlbauer%2Fdjango-signposting/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dnlbauer%2Fdjango-signposting/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dnlbauer","download_url":"https://codeload.github.com/dnlbauer/django-signposting/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225750180,"owners_count":17518315,"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","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":["django","fair","fair-data","links","linkset","rfc8288","signposting"],"created_at":"2024-11-23T11:09:38.343Z","updated_at":"2025-07-15T10:32:28.952Z","avatar_url":"https://github.com/dnlbauer.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Python package](https://github.com/dnlbauer/django-signposting/actions/workflows/python-package.yml/badge.svg)](https://github.com/dnlbauer/django-signposting/actions/workflows/python-package.yml)\n\n# FAIR signposting middleware for Django\n\n`django_signposting` is a Django middleware library that facilitates the addition of\nFAIR signposting headers to HTTP responses.\nThis middleware helps in making your data more FAIR (Findable, accessible, interoperable, reuseable) by\nembedding signposting headers in responses, guiding clients to relevant resources linked to the response content.\n\nBased on the [Signposting](https://github.com/stain/signposting) library.\n\n## Features\n- Automatically adds signposting headers to HTTP responses.\n- Signposts can be added manually or automatically be parsed from JSON-LD/schema.org\n- Supports multiple relation types with optional media type specification.\n- Easily integrable with existing Django applications.\n\n### Signposts are formatted and added as Link headers\n\n```bash\ncurl -I http://localhost:8000\nHTTP/2 200 \n...\nlink: \u003chttps://schema.org/Dataset\u003e ; rel=\"type\" ,\n      \u003chttps://orcid.org/0000-0001-9447-460X\u003e ; rel=\"author\" ,\n      \u003chttps://example.com/download.zip\u003e ; rel=\"item\" ; type=\"application/zip\"\n```\n\n## Installation\n\n```bash\npip install django-signposting\n```\n\n## Usage\n\n### Automatic parsing of JSON-LD\n\nThe library can automatically add signposts to web pages that already make\nmetadata available via JSON-LD in HTML via `\u003cscript type=\"application/ld+json\"\u003e` tags, i.e.:\n\n```HTML\n\u003c!DOCTYPE html\u003e\n\u003chtml\u003e\n\u003chead\u003e\n\n\u003cscript type=\"application/ld+json\"\u003e{\"@context\": \"https://schema.org\", \"@type\": [\"WebSite\", \"Dataset\"], \"author\": {\"@type\": \"Person\", \"name\": \"Daniel Bauer\", \"url\": \"https://orcid.org/0000-0001-9447-460X\"}, \"description\": \"A dataset of things.\", \"hasPart\": [{\"@type\": \"ImageObject\", \"encodingFormat\": \"image/png\", \"url\": \"http://example.com/image.png\"}, {\"@type\": \"ImageObject\", \"encodingFormat\": \"image/png\", \"url\": \"http://example.com/image2.png\"}], \"license\": {\"@type\": \"CreativeWork\", \"name\": \"CC BY 4.0\", \"url\": \"https://creativecommons.org/licenses/by/4.0/\"}, \"name\": \"My Dataset\", \"sameAs\": [{\"@type\": \"MediaObject\", \"contentUrl\": \"https://example.com/download.zip\", \"encodingFormat\": \"application/zip\"}, {\"@type\": \"MediaObject\", \"contentUrl\": \"https://example.com/metadata.json\"}], \"url\": \"https://example.com\"}\u003c/script\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n    \u003cp\u003eHello, world!\u003c/p\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\nTo enable automatic parsing of JSON-LD, add the following middleware classes to your Django project's MIDDLEWARE setting in settings.py:\n\n```python\nMIDDLEWARE = [\n    ...,\n    'django_signposting.middleware.SignpostingMiddleware',\n    'django_signposting.middleware.JsonLdSignpostingParserMiddleware',\n    ...,\n]\n```\n\nThis extracts supported metadatad properties from JSON-LD and adds the corresponding signposting headers to the `HttpResponse` automatically.\n\nAutomatic parsing is compatible with extensions that provide JSON-LD as part of a web page, such as [django-json-ld](https://pypi.org/project/django-json-ld/).\nIt can also extract signposts from rich metadata descriptions of datasets such as detached [RO-Crates](https://www.researchobject.org/ro-crate) (see [example views](./example/example/views.py)).\n\n\u003e Note: The middleware order is important! Place `SignpostingMiddleware` before `JsonLdSignpostingParserMiddleware` to ensure proper extraction and processing of JSON-LD content.\n\n## Alternative approaches\n\n### Manual signposting\n\nFor cases where there is no embedded JSON-LD, or you want to specify additional headers manually, you can use the `add_signposts` utility function.\nThis still requires the `SignpostingMiddleware` to inject the links into\nthe response:\n\n1. **Add Middleware**: Add the `SignpostingMiddleware` to your Django project's `MIDDLEWARE` setting in `settings.py`:\n\n```python\nMIDDLEWARE = [\n    ...,\n    'django_signposting.middleware.SignpostingMiddleware',\n    ...,\n]\n```\n\n2. **Add Signposts to your Views:** Use the `add_signposts` utility function:\n\n```python\nfrom django.http import HttpResponse\nfrom django_signposting.utils import add_signposts\nfrom signposting import Signpost, LinkRel\n\ndef my_view(request):\n    response = HttpResponse(\"Hello, world!\")\n    \n    # Add signpostings as string\n    add_signposts(\n        response,\n        Signpost(LinkRel.type, \"https://schema.org/Dataset\"),\n        Signpost(LinkRel.author, \"https://orcid.org/0000-0001-9447-460X\")\n        Signpost(LinkRel.item, \"https://example.com/download.zip\", \"application/zip\")\n    )\n\n    return response\n```\n\n### Manual parsing of JSON-LD\n\nIf you have metadata in JSON-LD available, but it is not rendered as part of the response, you can still parse it and add the signposting links manually:\n\n```python\nfrom django.http import HttpResponse\nfrom django_signposting.utils import add_signposts, jsonld_to_signposts\n\nresponse = HttpResponse(\"Hello World\")\njson_ld = {\n    \"@context\": \"http://schema.org/\",\n    \"@graph\": [\n        ...\n    ]\n}\nsignposts = jsonld_to_signposts(json_ld)\nadd_signposts(response, **signposts)\n```\n\n### Add signposts as HTML links instead of headers\n\nIn cases where you want to include signposting directly in the HTML response rather than as HTTP headers\n(for example because headers are overwritten by a proxy or something else),\nyou can use the `HtmlSignpostingMiddleware` instead of `SignpostingMiddleware`.\n\nThis middleware automatically adds \u003clink\u003e elements to the HTML \u003chead\u003e section based\non the detected signposting metadata and produces output similar to the one shown here:\n\n```HTML\n\u003c!DOCTYPE html\u003e\n\u003chtml\u003e\n \u003chead\u003e\n  (...)\n  \u003clink href=\"http://schema.org/WebSite\" rel=\"type\"/\u003e\n  \u003clink href=\"http://schema.org/Dataset\" rel=\"type\"/\u003e\n  \u003clink href=\"https://orcid.org/0000-0001-9447-460X\" rel=\"author\"/\u003e\n  \u003clink href=\"https://creativecommons.org/licenses/by/4.0/\" rel=\"license\"/\u003e\n  \u003clink href=\"https://example.com\" rel=\"cite-as\"/\u003e\n  \u003clink href=\"https://example.com/download.zip\" rel=\"describedby\" type=\"application/zip\"/\u003e\n  \u003clink href=\"https://example.com/metadata.json\" rel=\"describedby\"/\u003e\n  \u003clink href=\"http://example.com/image.png\" rel=\"item\" type=\"image/png\"/\u003e\n  \u003clink href=\"http://example.com/image2.png\" rel=\"item\" type=\"image/png\"/\u003e\n \u003c/head\u003e\n ...\n\u003c/html\u003e\n```\n\n## TODO\n\n- [ ] Add support for link sets\n- [ ] Add support for specifying profile extension attribute\n\n## License\n\nLicensed under the MIT License.\n\n## References\n\nYou can cite this library using this DOI: [10.5281/zenodo.15008517](https://doi.org/10.5281/zenodo.15008517).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdnlbauer%2Fdjango-signposting","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdnlbauer%2Fdjango-signposting","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdnlbauer%2Fdjango-signposting/lists"}