{"id":13813604,"url":"https://github.com/globocom/pluct","last_synced_at":"2026-01-10T14:45:27.271Z","repository":{"id":57453654,"uuid":"9673434","full_name":"globocom/pluct","owner":"globocom","description":"A JSON Hyper Schema client that allows hypermedia navigation and resource validation","archived":true,"fork":false,"pushed_at":"2017-03-27T12:00:28.000Z","size":212,"stargazers_count":38,"open_issues_count":7,"forks_count":12,"subscribers_count":53,"default_branch":"master","last_synced_at":"2025-04-06T08:36:38.925Z","etag":null,"topics":[],"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/globocom.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-04-25T14:18:00.000Z","updated_at":"2023-12-15T02:59:08.000Z","dependencies_parsed_at":"2022-08-29T11:11:49.540Z","dependency_job_id":null,"html_url":"https://github.com/globocom/pluct","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/globocom%2Fpluct","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/globocom%2Fpluct/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/globocom%2Fpluct/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/globocom%2Fpluct/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/globocom","download_url":"https://codeload.github.com/globocom/pluct/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253572565,"owners_count":21929612,"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":[],"created_at":"2024-08-04T04:01:22.809Z","updated_at":"2026-01-10T14:45:27.209Z","avatar_url":"https://github.com/globocom.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"pluct\n=====\n\n.. image:: https://travis-ci.org/globocom/pluct.svg\n    :target: https://travis-ci.org/globocom/pluct\n    :alt: Travis CI Build Status\n\nA JSON Hyper Schema client that allows hypermedia navigation and\nresource validation.\n\nBasic Usage\n-----------\n\n.. code:: python\n\n    import pluct\n\n    # Load a resource\n    item = pluct.resource('http://myapi.com/api/item', timeout=2)  # Works with connect timeout\n\n    # Verifying if the resource is valid for the current schema\n    item.is_valid()\n\n    # Use the resource as a dictionary\n    first_title = item['subitems'][0]['title']\n\n    # Accessing the item schema\n    item.schema['properties']['title']\n\n    # Loading a related resource\n    category = item.rel('category')\n\n    # With additional parameters\n    category = item.rel('category', timeout=(1, 2))  # You can choose from request parameters: http://docs.python-requests.org/en/latest/api/#requests.Session.request\n\nAuthentication / Custom HTTP Client\n-----------------------------------\n\n``Pluct`` uses the `Session \u003chttp://docs.python-requests.org/en/latest/api/#request-sessions\u003e`_\nobject from the `requests \u003chttp://docs.python-requests.org/en/latest/\u003e`_ package as a HTTP client.\n\nAny other client with the same interface can be used.\n\nHere is an example using `alf \u003chttps://github.com/globocom/alf\u003e`_, an OAuth 2 client:\n\n.. code:: python\n\n    from pluct import Pluct\n    from alf.client import Client\n\n    alf = Client(\n        token_endpoint='http://myapi.com/token',\n        client_id='client-id',\n        client_secret='secret')\n\n    # Create a pluct session using the client\n    pluct = Pluct(client=alf)\n    item = pluct.resource('http://myapi.com/api/item')\n\nAll subsequent requests for schemas or resources in this session will\nuse the same client.\n\nParameters and URI expansion\n----------------------------\n\n`URI Templates \u003chttp://tools.ietf.org/html/rfc6570\u003e`_ are supported when following resource links.\n\nThe context for URL expansion will be a merge of the resource ``data``\nattribute and the ``params`` parameter passed to the resource’s ``rel``\nmethod.\n\nAny variable not consumed by the URL Template will be used on the query\nstring for the request.\n\nBetter explained in an example. Consider the following resource and\nschema snippets:\n\n.. code:: json\n\n    {\n        \"type\": \"article\"\n    }\n\n.. code:: json\n\n    {\n        \"...\": \"...\",\n        \"links\": [\n            {\n                \"rel\": \"search\",\n                \"href\": \"/api/search/{type}\"\n            }\n        ]\n    }\n\nThe next example will resolve the ``href`` from the ``search`` link to\n``/api/search/article?q=foo`` and will load articles containing the text\n“foo”:\n\n.. code:: python\n\n    import pluct\n\n    # Load a resource\n    item = pluct.resource('http://myapi.com/api/item')\n\n    articles = item.rel('search', params={'q': 'foo'})\n\nTo search for galleries is just a matter of passing a different ``type``\nin the ``params`` argument, as follows:\n\n.. code:: python\n\n    galleries = item.rel('search', params={'type': 'gallery', 'q': 'foo'})\n\nTo send your own body data you can send the object as data. This will follow\nyour method (PUT, POST, GET or DELETE) with all data from object:\n\n.. code:: python\n\n    galleries = item.rel('create', data=item)\n\n\nSchema loading\n--------------\n\nWhen a resource is loaded, a lazy-schema schema will be created and its\ndata will only be loaded when accessed.\n\n``Pluct`` looks for a schema URL on the ``profile`` parameter of the\n``Content-type`` header:\n\n.. code:: python\n\n    Content-Type: application/json; profile=\"http://myapi.com/api/schema\"\n\nReferences ($ref)\n-----------------\n\n`JSON Pointers \u003chttps://tools.ietf.org/html/rfc6901\u003e`_ on schemas are\nalso supported.\n\nPointers are identified by a dictionary with a ``$ref`` key pointing to an\nexternal URL or a local pointer.\n\nConsidering the following definitions on the ``/api/definitions`` url:\n\n.. code:: json\n\n    {\n        \"address\": {\n            \"type\": \"object\",\n            \"properties\": {\n                \"line1\": {\"type\": \"string\"},\n                \"line2\": {\"type\": \"string\"},\n                \"zipcode\": {\"type\": \"integer\"},\n            }\n        }\n    }\n\nAnd this schema on ``/api/schema`` that uses the above definitions:\n\n.. code:: json\n\n    {\n        \"properties\": {\n            \"shippingAddress\": {\"$ref\": \"http://myapi.com/api/definitions#/address\"},\n            \"billingAddress\": {\"$ref\": \"http://myapi.com/api/definitions#/address\"},\n        }\n    }\n\nThe ``billingAddress`` can be accessed as follows:\n\n.. code:: python\n\n    import pluct\n    schema = pluct.schema('http://myapi.com/api/schema')\n\n    schema['properties']['billingAddress']['zipcode'] == {\"type\": \"integer\"}\n\nContributing\n------------\n\nFork the repository on Github:\nhttps://github.com/globocom/pluct\n\nCreate a virtualenv and install the dependencies:\n\n.. code:: bash\n\n    make setup\n\nTests are on the `pluct/tests` directory, run the test suite with:\n\n.. code:: bash\n\n    make test\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fglobocom%2Fpluct","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fglobocom%2Fpluct","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fglobocom%2Fpluct/lists"}