{"id":26990388,"url":"https://github.com/pablo-moreno/spook","last_synced_at":"2025-04-03T21:37:58.069Z","repository":{"id":46051371,"uuid":"278843416","full_name":"pablo-moreno/spook","owner":"pablo-moreno","description":"Django Rest Framework extension to interconnect external HTTP APIs.","archived":false,"fork":false,"pushed_at":"2022-09-29T10:51:16.000Z","size":2338,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-13T00:04:32.851Z","etag":null,"topics":["django","django-rest-framework","external-api"],"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/pablo-moreno.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}},"created_at":"2020-07-11T10:57:01.000Z","updated_at":"2022-10-21T18:38:17.000Z","dependencies_parsed_at":"2022-09-26T18:30:50.780Z","dependency_job_id":null,"html_url":"https://github.com/pablo-moreno/spook","commit_stats":null,"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pablo-moreno%2Fspook","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pablo-moreno%2Fspook/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pablo-moreno%2Fspook/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pablo-moreno%2Fspook/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pablo-moreno","download_url":"https://codeload.github.com/pablo-moreno/spook/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247085972,"owners_count":20881157,"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","django-rest-framework","external-api"],"created_at":"2025-04-03T21:37:57.613Z","updated_at":"2025-04-03T21:37:58.051Z","avatar_url":"https://github.com/pablo-moreno.png","language":"Python","readme":"# Django Spook\r\n\r\n[![PyPI](https://img.shields.io/pypi/v/spook?style=flat-square)](https://pypi.org/project/spook/)\r\n[![codecov](https://codecov.io/gh/pablo-moreno/spook/branch/master/graph/badge.svg?token=6ZAHAHZG7Z)](https://codecov.io/gh/pablo-moreno/spook/)\r\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\r\n[![PyPI - Downloads](https://img.shields.io/pypi/dm/spook)](https://pypistats.org/packages/spook)\r\n\r\nLibrary to interconnect multiple external HTTP APIs as Http Resources\r\n\r\n## Installation\r\n\r\n```bash\r\npip install spook\r\n```\r\n\r\n## Usage\r\n\r\nDeclare a serializer class for your input validation\r\n\r\n```python\r\n# app/serializers.py\r\nfrom rest_framework import serializers\r\n\r\nclass MySerializer(serializers.ModelSerializer):\r\n    name = serializers.CharField()\r\n    age = serializers.IntegerField()\r\n    \r\n    class Meta:\r\n        fields = ('name', 'age', )\r\n```\r\n\r\nDeclare an InputValidator\r\n\r\n```python\r\n# app/validators.py\r\nfrom spook.validators import InputValidator\r\nfrom app.serializers import MySerializer\r\n\r\n\r\nclass MyResourceInputValidator(InputValidator):\r\n    serializer_class = MySerializer\r\n```\r\n\r\n\r\nDeclare an API Resource class.\r\n\r\n```python\r\n# app/resources.py\r\nfrom spook.resources import APIResource\r\nfrom app.validators import MyResourceInputValidator\r\n\r\n\r\nclass MyResource(APIResource):\r\n    api_url = 'https://my.external/api'\r\n    validator = MyResourceInputValidator\r\n```\r\n\r\nNow you can instance MyResource class and use the methods\r\n\r\n```python\r\nresource = MyResource()\r\n\r\n# List resources\r\nresource.list()\r\n\r\n# Retrieve a single resource\r\nresource.retrieve(pk=1)\r\n\r\n# Create resource\r\nresource.create({'name': 'Pablo', 'age': 28})\r\n\r\n# Update resource\r\nresource.update(pk=1, data={'name': 'Pablo Moreno'})\r\n\r\n# Delete resource\r\nresource.delete(pk=1)\r\n```\r\n\r\nThere are also some views available\r\n\r\n```python\r\n# app/views.py\r\nfrom spook.views import (\r\n    APIResourceRetrieveView, APIResourceListView, APIResourceCreateView, APIResourcePutView,\r\n    APIResourceRetrieveUpdateView, APIResourceRetrieveUpdateDestroyView, APIResourceListCreateView,\r\n)\r\nfrom app.resources import ProductResource\r\n\r\n\r\nclass ListCreateProductResourceView(APIResourceListCreateView):\r\n    resource = ProductResource\r\n\r\n    def get_token(self, request):\r\n        return ''  # We need to override get_token()\r\n\r\n\r\nclass RetrieveUpdateDestroyProductResourceView(APIResourceRetrieveUpdateDestroyView):\r\n    resource = ProductResource\r\n\r\n    def get_token(self, request):\r\n        return ''\r\n```\r\n\r\n## Development\r\n\r\n\u003e We recommend to use a virtual environment\r\n\r\n**Install poetry**\r\n\r\n```python\r\npip install poetry\r\n```\r\n\r\n**Install dependencies**\r\n\r\n```python\r\npoetry install\r\n```\r\n\r\n**Run tests**\r\n\r\n```python\r\npoetry run pytest --cov=spook\r\n```\r\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpablo-moreno%2Fspook","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpablo-moreno%2Fspook","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpablo-moreno%2Fspook/lists"}