{"id":21445760,"url":"https://github.com/legolasvzla/django-rest-framework-orientdb-postgresql","last_synced_at":"2026-04-18T17:03:21.036Z","repository":{"id":41944516,"uuid":"188330348","full_name":"LegolasVzla/django-rest-framework-orientdb-postgresql","owner":"LegolasVzla","description":"Integration between django rest framework with orientdb (OGM) and postgresql (ORM)","archived":false,"fork":false,"pushed_at":"2022-12-08T05:13:09.000Z","size":96,"stargazers_count":1,"open_issues_count":7,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-17T01:23:12.323Z","etag":null,"topics":["django","django-rest-framework","orientdb","postgresql","pyorient","python3"],"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/LegolasVzla.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":"2019-05-24T01:20:25.000Z","updated_at":"2019-11-16T20:43:49.000Z","dependencies_parsed_at":"2023-01-24T11:40:18.390Z","dependency_job_id":null,"html_url":"https://github.com/LegolasVzla/django-rest-framework-orientdb-postgresql","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/LegolasVzla/django-rest-framework-orientdb-postgresql","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LegolasVzla%2Fdjango-rest-framework-orientdb-postgresql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LegolasVzla%2Fdjango-rest-framework-orientdb-postgresql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LegolasVzla%2Fdjango-rest-framework-orientdb-postgresql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LegolasVzla%2Fdjango-rest-framework-orientdb-postgresql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LegolasVzla","download_url":"https://codeload.github.com/LegolasVzla/django-rest-framework-orientdb-postgresql/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LegolasVzla%2Fdjango-rest-framework-orientdb-postgresql/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31976806,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-18T16:27:12.723Z","status":"ssl_error","status_checked_at":"2026-04-18T16:27:11.140Z","response_time":103,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["django","django-rest-framework","orientdb","postgresql","pyorient","python3"],"created_at":"2024-11-23T02:38:26.170Z","updated_at":"2026-04-18T17:03:21.019Z","avatar_url":"https://github.com/LegolasVzla.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# django-rest-framework-orientdb-postgresql\n\n- [Django REST framework](https://www.django-rest-framework.org/) is a powerful and flexible toolkit for building Web APIs.\n\n- [Orientdb](https://orientdb.com/) is the first multi-model database. Fastest graph database\n\n- [PostgreSQL](https://www.postgresql.org/) is the World's Most Advanced Open Source Relational Database\n\nWhat would happen if we integrate this technologies?...Let's check it!\n\n## Requirements\n- Ubuntu 18\n- Orientdb: follow [next steps](https://computingforgeeks.com/how-to-install-and-configure-orientdb-on-ubuntu-18-04-lts/) to install it\n- Install PostgreSQL:\n```\n  sudo apt-get update\n  sudo apt install python3-dev postgresql postgresql-contrib python3-psycopg2 libpq-dev\n```\n## Installation\n\nCreate your virtualenv (see Troubleshooting section) and install the requirements:\n\n\tvirtualenv env --python=python3\n\tsource env/bin/activate\n\n\tpip install -r requirements.txt\n\nCreate logs folder:\n\n\tmkdir logs\n\nThe structure of the **settings.ini** file, is described below:\n\n\t[postgresdbConf]\n\tDB_ENGINE=django.db.backends.postgresql\n\tDB_NAME=dbname\n\tDB_USER=user\n\tDB_PASS=password\n\tDB_HOST=host\n\tDB_PORT=port\n\n\t[orientdbConf]\n\tDB_NAME=dbname\n\tDB_USER=user\n\tDB_PASS=password\n\tDB_HOST=host\n\tDB_PORT=host\n\nFill in with your own PostgreSQL and OrientDB credentials. By default, DB_HOST and DB_PORT in PostgreSQL are localhost/5432 and in OrientDB localhost/2424 (OrientDB Studio is 2480).\n\nRun the migrations (to PostgreSQL):\n\n\tpython manage.py makemigrations\n\n\tpython manage.py migrate\n\nRun the server:\n\n\tpython manage.py runserver\n\nYou could see the home page in:\n\n\thttp://127.0.0.1:8000/\n\n## Models\n\nThere are 4 main models :\n- Users: are stored in postgreSQL\n- Companies: are stored in postgreSQL\n- OFriends: relationship between two users. Are stored in OrientDB\n- OWorksat: relationship between a user and a company. Are stored in OrientDB\n\nAlso if a relationship is created, either an OUser or OCompany instance vertex are created in OrientDB with only the ID's from postgreSQL, to allow the creation of the relationship (edges). This is a possible way to \"Join\" postgreSQL (e.g. structure) and orientdb (graph querys) strengths.\n\nYou can play with the Orientdb models and delete them easily by console. In your terminal, access to the orientdb path:\n\n\tsudo /opt/orientdb/bin/console.sh\n\nSwitch to your database:\n\n\tconnect remote:localhost/databases/\u003cyour_database_name\u003e root orientdb\n\nYou can do changes in your orientdb data and finally, you can delete your orientdb objects:\n\n\tdelete edge ofriends;\n\tdelete edge oworksat;\n\tdrop class Ofriends;\n\tdrop class Oworksat;\n\tdelete vertex from OUsers;\n\tdelete vertex from OCompany;\n\tdrop class OUsers;\n\tdrop class OCompany;\n\nAnd when you run django server, it will generate all the models again, similar to \"python manage.py migrate\" command.\n\n## Swagger Documentation\n\n[Swagger UI](https://swagger.io/tools/swagger-ui/) is a tool for API documentation. \"Swagger UI allows anyone — be it your development team or your end consumers — to visualize and interact with the API’s resources without having any of the implementation logic in place. It’s automatically generated from your OpenAPI (formerly known as Swagger) Specification, with the visual documentation making it easy for back end implementation and client side consumption.\"\n\n## Endpoints Structure\nIn a RESTful API, endpoints (URLs) define the structure of the API and how end users access data from our application using the HTTP methods (GET, POST, PUT, DELETE), making all posssible CRUD (create, retrieve, update, delete) operations.\n\nYou can see the endpoints structure in the Swagger UI documentation:\n\t\n\thttp://127.0.0.1:8000/swagger/\n\nBasically the structure is as below for all the instances (User, Company, OFriends, OWorksat)\n\nEndpoint |HTTP Method | CRUD Method | Result\n-- | -- |-- |--\n`api/\u003cinstance\u003e` | GET | READ | Get all the '\u003cinstance\u003e' records\n`api/\u003cinstance\u003e/:id` | GET | READ | Get a single \u003cinstance\u003e (at the moment, only for User and Company instances) reacord\n`api/\u003cinstance\u003e`| POST | CREATE | Create a new \u003cinstance\u003e record\n`api/\u003cinstance\u003e/:id` | PUT | UPDATE | Update a \u003cinstance\u003e (at the moment, only for User and Company instances) record\n`api/\u003cinstance\u003e/:id` | DELETE | DELETE | Delete a \u003cinstance\u003e (for relationships, only works in swagger UI DELETE method) record\n\n## Testing the API\n\nExists many ways to test the API. \n\nBy your terminal:\n- Using [curl](https://curl.haxx.se/)\n- Using [httpie](https://github.com/jakubroztocil/httpie#installation), which is a user friendly http client that's written in Python, and it's in the requirements.txt file.\n\nBy the DRF UI or Swagger UI:\n- In the basic root view for DefaultRouter of DRF: http://127.0.0.1:8000/\n- In the swagger UI: http://127.0.0.1:8000/swagger/\n\nAlso you can use postman.\n\n## Getting Token Authentication for your Superuser\n\nWith the Django's development server up, only authenticated users can use the User API service, for that reason if you try in your terminal this (even without any data):\n\n\thttp  http://127.0.0.1:8000/api/user/1/\n\nYou get:\n```\n{\n    \"detail\": \"Authentication credentials were not provided.\"\n}\n```\nSo, you need to generate your DRF token authentication. First, create your superuser by django createsuperuser command:\n\n\tpython manage.py createsuperuser\n\nAnd fill up an **email** and a **password** to generate a superuser in postgreSQL. You could generate another user if you want to make \"OFriends\" relationship.\n\nThen, generate you need to generate your token. You have 2 ways:\n\n1. By rest_auth UI. Go to:\n\n\thttp://127.0.0.1:8000/rest-auth/login/\n\nAnd fill up with your **email** (username and email) and **password** superuser, send the POST request and that's it, now you have your token!\n\n2. By rest_framework.authtoken. In your terminal write:\n\n\tpython manage.py drf_create_token \u003cyour_superuser_email\u003e\n\nAnd you get your token. Now you can access to the User Api. Copy your token and make the request:\n\n\thttp http://127.0.0.1:8000/api/user/1/ 'Authorization: Token \u003cyour_token\u003e'\n\nAlso, in the DRF User API, you could access in the form:\n\n\thttp://127.0.0.1:8000/api/user/1/?auth_token=\u003cyour_token\u003e\n\n## Generating Companies\n\na) By sending a POST request in the Company API:\n\n\thttp://127.0.0.1:8000/api/company\n\nb) Or by sending a POST Company request in the swagger UI:\n\n\thttp://127.0.0.1:8000/swagger/\n\t\nThen make a GET request to get Company ID.\n\nYour Company will be generated in PostgreSQL database. \n\n## Generating Orientdb relationships\n\nDo you want to generate \"friends\" or \"works at\" relationship?. According your choice, make a POST request in:\n\n- http://127.0.0.1:8000/api/ofriends (OFriends relationship) with the two Users ID generated before\n- http://127.0.0.1:8000/api/oworksat (OWorksat relationship) with the User and Company ID generated before\n\nBoth objects will be generated in orientdb database. Finally you could make a GET request in:\n\n- http://127.0.0.1:8000/api/ofriends (OFriends relationship)\n- http://127.0.0.1:8000/api/oworksat (OFriends relationship)\n\nAnd you could see your recently relationship generated. Also you can send a GET request (OFriends or OFriend) in swagger UI to see the instance created.\n\nIf you want to delete and edge (OFriends,OWorksat), you can do it by accessing to Orientdb Studio (or by orientdb console), i.e:\n\n\thttp://localhost:2480/studio/index.html#/\n\n\nExecute your query, similar as below:\n\n\tselect * from `\u003cyour_edge\u003e`\n\nAnd take note of your @rid (see Troubleshooting section). Finally, send a delete request in swagger UI, passing the @rid:\n\n\thttp://127.0.0.1:8000/swagger/\n\nYou could find more pyorient OGM documentation in the [official repository](https://github.com/orientechnologies/pyorient/blob/master/OGM.md) or in the [home page](https://orientdb.com/docs/2.2.x/PyOrient-OGM.html).\n\n## Troubleshooting\n\n1. About pyorient:\n\nPyorient stable version is \"1.5.5\", but it has a current [issue](https://github.com/orientechnologies/pyorient/issues/27#issuecomment-410819253), so inside of your virtualenv:\n\n\tenv/lib/python3.6/site-packages/pyorient\n\nOpen **orient.py** and comment this block of code (from 100 to 103 line):\n```\nif self.protocol \u003e SUPPORTED_PROTOCOL:\n        raise PyOrientWrongProtocolVersionException(\n            \"Protocol version \" + str(self.protocol) +\n            \" is not supported yet by this client.\", []) \n```\n\n2. About delete/destroy method using pyorient OGM:\n\nI created an [issue](https://github.com/mogui/pyorient/issues/284) with the intention to search for a better way to delete and edge instead of using simple raw query, so in the api.py, i had to use a pyorient client to do that:\n```\ndef destroy(self, request, *args, **kwargs):\n\tclient = orientdbConnection()\n\n\tclient.command(\"delete edge \u003cmy_edge\u003e where @rid = '\" + kwargs['pk'] + \"'\")\n\t\n\treturn Response(status=status.HTTP_204_NO_CONTENT)\n```\n\nObviously this is not what it should be, but it's a solution. Even with this, I couldn't find a susccessfully way to pass in the DRF querystring, an orientdb @rid to delete an edge, I only achieved this in the swagger UI delete request (if you find how to do that, please tell me)\n\n\n## Contributions\n------------------------\n\nAll work to improve performance is good\n\nEnjoy it!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flegolasvzla%2Fdjango-rest-framework-orientdb-postgresql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flegolasvzla%2Fdjango-rest-framework-orientdb-postgresql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flegolasvzla%2Fdjango-rest-framework-orientdb-postgresql/lists"}