{"id":21833126,"url":"https://github.com/null-none/django-jsonrpc","last_synced_at":"2025-03-21T13:45:17.842Z","repository":{"id":146603038,"uuid":"453459856","full_name":"null-none/django-jsonrpc","owner":"null-none","description":"Django JSON-RPC","archived":false,"fork":false,"pushed_at":"2022-03-10T18:41:13.000Z","size":110,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-26T09:28:39.557Z","etag":null,"topics":["json-rpc","json-rpc2","python","python3"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/null-none.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,"publiccode":null,"codemeta":null}},"created_at":"2022-01-29T16:57:38.000Z","updated_at":"2023-03-10T07:07:22.000Z","dependencies_parsed_at":null,"dependency_job_id":"7c43b44e-2fce-4132-9605-6b4890c45169","html_url":"https://github.com/null-none/django-jsonrpc","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/null-none%2Fdjango-jsonrpc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/null-none%2Fdjango-jsonrpc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/null-none%2Fdjango-jsonrpc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/null-none%2Fdjango-jsonrpc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/null-none","download_url":"https://codeload.github.com/null-none/django-jsonrpc/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244807436,"owners_count":20513641,"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":["json-rpc","json-rpc2","python","python3"],"created_at":"2024-11-27T19:28:15.944Z","updated_at":"2025-03-21T13:45:17.832Z","avatar_url":"https://github.com/null-none.png","language":"Python","readme":"Django JSON-RPC\n===============\n\nA basic JSON-RPC Implementation for your Django-powered sites.\n\nFeatures:\n\n* Simple, pythonic API\u003c/li\u003e\n* Support for Django authentication\u003c/li\u003e\n* Supports JSON-RPC 1.0, 1.1, 1.2 and 2.0 Spec\n* Proxy to test your JSON Service\n* Run-time type checking\n* Graphical JSON-RPC browser and web console\n* Provides `system.describe`\n\n\nThe basic API:\n\n**myproj/myapp/views.py**\n\n    from jsonrpc import jsonrpc_method\n\n    @jsonrpc_method('myapp.sayHello')\n    def whats_the_time(request, name='Lester'):\n      return \"Hello %s\" % name\n\n    @jsonrpc_method('myapp.gimmeThat', authenticated=True)\n    def something_special(request, secret_data):\n      return {'sauce': ['authenticated', 'sauce']}\n\n\n**myproj/urls.py**\n\n    from django.urls import include, path, re_path\n\n    from jsonrpc.site import jsonrpc_site\n    from jsonrpc import views\n\n    urlpatterns = (\n      path('^json/browse/', views.browse, name='jsonrpc_browser'),\n      path('^json/', jsonrpc_site.dispatch, name='jsonrpc_mountpoint'),\n      re_path(r'^json/(?P\u003cmethod\u003e[a-zA-Z0-9.-_]+)$', jsonrpc_site.dispatch),\n    )\n\n\n**To test your service:**\nYou can test your service using the provided graphical browser and console,\navailable at http://YOUR_URL/json/browse/ (if using the url patterns from above) or with the included ServiceProxy:\n\n    \u003e\u003e\u003e from jsonrpc.proxy import ServiceProxy\n\n    \u003e\u003e\u003e s = ServiceProxy('http://localhost:8080/json/')\n\n    \u003e\u003e\u003e s.myapp.sayHello('Sam')\n    {u'error': None, u'id': u'jsonrpc', u'result': u'Hello Sam'}\n\n    \u003e\u003e\u003e s.myapp.gimmeThat('username', 'password', 'test data')\n    {u'error': None, u'id': u'jsonrpc', u'result': {u'sauce': [u'authenticated', u'sauce']}}\n\nWe add the `jsonrpc_version` variable to the request object. It be either '1.0', '1.1' or '2.0'. Arg.\n\nGuide\n=====\n\n### Adding JSON-RPC to your application\n\n#### 1. Install django-jsonrpc\n\n    pip install django-jsonrpc\n\n    # Add 'jsonrpc' to your INSTALLED_APPS in your settings.py file\n\n#### 2. Write JSON-RPC methods\n\n    from jsonrpc import jsonrpc_method\n\n    @jsonrpc_method('app.register')\n    def register_user(request, username, password):\n      u = User.objects.create_user(username, 'internal@app.net', password)\n      u.save()\n      return u.__dict__\n\n    @jsonrpc_method('app.change_password', authenticated=True)\n    def change_password(request, new_password):\n      request.user.set_password(new_password)\n      request.user.save()\n      return u.__dict__\n\n#### 3. Add the JSON-RPC mountpoint and import your views\n\n    from jsonrpc import jsonrpc_site\n    import app.views\n\n    urlpatterns = patterns('',\n      url(r'^json/$', jsonrpc_site.dispatch, name='jsonrpc_mountpoint'),\n      # ... among your other URLs\n    )\n\n\n### The jsonrpc_method decorator\nWraps a function turns it into a json-rpc method. Adds several attributes to the function speific to the JSON-RPC machinery and adds it to the default jsonrpc_site if one isn't provided. You must import the module containing these functions in your urls.py.\n\n`jsonrpc.jsonrpc_method(name, authenticated=False, safe=False, validate=False)`\n\u003cul\u003e\n\u003cli\u003e\n`name`\n\nThe name of your method. IE: `namespace.methodName`\n\u003c/li\u003e\n\u003cli\u003e\n`authenticated=False`\n\nAdds `username` and `password` arguments to the beginning of your method if the user hasn't already been authenticated. These will be used to authenticate the user against `django.contrib.authenticate` If you use HTTP auth or other authentication middleware, `username` and `password` will not be added, and this method will only check against `request.user.is_authenticated`.\n\nYou may pass a callablle to replace `django.contrib.auth.authenticate` as the authentication method. It must return either a User or `None` and take the keyword arguments `username` and `password`.\n\u003c/li\u003e\n\u003cli\u003e\n`safe=False`\n\nDesignates whether or not your method may be accessed by HTTP GET. By default this is turned off.\n\u003c/li\u003e\n\u003cli\u003e\n`validate=False`\n\nValidates the arguments passed to your method based on type information provided in the signature. Supply type information by including types in your method declaration. Like so:\n\n      @jsonrpc_method('myapp.specialSauce(Array, String)', validate=True)\n      def special_sauce(self, ingredients, instructions):\n        return SpecialSauce(ingredients, instructions)\n\nCalls to `myapp.specialSauce` will now check each arguments type before calling `special_sauce`, throwing an `InvalidParamsError` when it encounters a discrepancy. This can significantly reduce the amount of code required to write JSON-RPC services.\n\n*NOTE:* Type checking is only available on Python versions 2.6 or greater.\n\u003c/li\u003e\n\u003cli\u003e\n`site=default_site`\n\nDefines which site the jsonrpc method will be added to. Can be any\nobject that provides a `register(name, func)` method.\n\u003c/li\u003e\n\u003c/ul\u003e\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnull-none%2Fdjango-jsonrpc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnull-none%2Fdjango-jsonrpc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnull-none%2Fdjango-jsonrpc/lists"}