{"id":19028294,"url":"https://github.com/rethinkdb/rethinkdb-python","last_synced_at":"2025-04-04T11:16:47.978Z","repository":{"id":37548233,"uuid":"134593743","full_name":"rethinkdb/rethinkdb-python","owner":"rethinkdb","description":"Python driver for RethinkDB","archived":false,"fork":false,"pushed_at":"2023-12-19T21:26:51.000Z","size":2644,"stargazers_count":65,"open_issues_count":40,"forks_count":34,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-03-28T10:11:18.918Z","etag":null,"topics":["python","rethinkdb","rethinkdb-driver"],"latest_commit_sha":null,"homepage":"https://rethinkdb.com/api/python/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rethinkdb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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},"funding":{"github":null,"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":"rethinkdb","liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2018-05-23T15:58:14.000Z","updated_at":"2025-01-21T16:16:11.000Z","dependencies_parsed_at":"2022-09-07T10:52:48.241Z","dependency_job_id":"8e101da4-412e-43a0-87a7-a39a67a85bf4","html_url":"https://github.com/rethinkdb/rethinkdb-python","commit_stats":{"total_commits":1117,"total_committers":87,"mean_commits":"12.839080459770114","dds":0.837958818263205,"last_synced_commit":"bc1a75a8a1126999afe3b70112a7fcad8e3b9624"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rethinkdb%2Frethinkdb-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rethinkdb%2Frethinkdb-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rethinkdb%2Frethinkdb-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rethinkdb%2Frethinkdb-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rethinkdb","download_url":"https://codeload.github.com/rethinkdb/rethinkdb-python/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247166171,"owners_count":20894654,"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":["python","rethinkdb","rethinkdb-driver"],"created_at":"2024-11-08T21:10:34.815Z","updated_at":"2025-04-04T11:16:47.958Z","avatar_url":"https://github.com/rethinkdb.png","language":"Python","funding_links":["https://funding.communitybridge.org/projects/rethinkdb"],"categories":[],"sub_categories":[],"readme":"# RethinkDB Python driver\n[![PyPI version](https://badge.fury.io/py/rethinkdb.svg)](https://badge.fury.io/py/rethinkdb) [![Build Status](https://travis-ci.org/rethinkdb/rethinkdb-python.svg?branch=master)](https://travis-ci.org/rethinkdb/rethinkdb-python) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/2b5231a6f90a4a1ba2fc795f8466bbe4)](https://www.codacy.com/app/rethinkdb/rethinkdb-python?utm_source=github.com\u0026amp;utm_medium=referral\u0026amp;utm_content=rethinkdb/rethinkdb-python\u0026amp;utm_campaign=Badge_Grade) [![Codacy Badge](https://api.codacy.com/project/badge/Coverage/2b5231a6f90a4a1ba2fc795f8466bbe4)](https://www.codacy.com/app/rethinkdb/rethinkdb-python?utm_source=github.com\u0026utm_medium=referral\u0026utm_content=rethinkdb/rethinkdb-python\u0026utm_campaign=Badge_Coverage)\n\n## Overview\n\n### What is RethinkDB?\nRethinkDB is the first open-source scalable database built for realtime applications. It exposes a new database access model -- instead of polling for changes, the developer can tell the database to continuously push updated query results to applications in realtime. RethinkDB allows developers to build scalable realtime apps in a fraction of the time with less effort.\n\n## Installation\n```bash\n$ pip install rethinkdb\n```\n*Note: this package is the extracted driver of RethinkDB's original python driver.*\n\n## Quickstart\nThe main difference with the previous driver (except the name of the package) is we are **not** importing RethinkDB as `r`. If you would like to use `RethinkDB`'s python driver as a drop in replacement, you should do the following:\n\n```python\nfrom rethinkdb import r\n\nconnection = r.connect(db='test')\n```\n\n## Blocking and Non-blocking I/O\nThis driver supports blocking I/O (i.e. standard Python sockets) as well as\nnon-blocking I/O through multiple async frameworks:\n\n* [Asyncio](https://docs.python.org/3/library/asyncio.html)\n* [Gevent](http://www.gevent.org/)\n* [Tornado](https://www.tornadoweb.org/en/stable/)\n* [Trio](https://trio.readthedocs.io/en/latest/)\n* [Twisted](https://twistedmatrix.com/trac/)\n\nThe following examples demonstrate how to use the driver in each mode.\n\n### Default mode (blocking I/O)\nThe driver's default mode of operation is to use blocking I/O, i.e. standard Python\nsockets. This example shows how to create a table, populate with data, and get every\ndocument.\n\n```python\nfrom rethinkdb import r\n\nconnection = r.connect(db='test')\n\nr.table_create('marvel').run(connection)\n\nmarvel_heroes = r.table('marvel')\nmarvel_heroes.insert({\n    'id': 1,\n    'name': 'Iron Man',\n    'first_appearance': 'Tales of Suspense #39'\n}).run(connection)\n\nfor hero in marvel_heroes.run(connection):\n    print(hero['name'])\n```\n\n### Asyncio mode\nAsyncio mode is compatible with Python ≥ 3.5.\n\n```python\nimport asyncio\nfrom rethinkdb import r\n\nasync def main():\n    async with await r.connect(db='test') as connection:\n        await r.table_create('marvel').run(connection)\n\n        marvel_heroes = r.table('marvel')\n        await marvel_heroes.insert({\n            'id': 1,\n            'name': 'Iron Man',\n            'first_appearance': 'Tales of Suspense #39'\n        }).run(connection)\n\n        # \"async for\" is supported in Python ≥ 3.6. In earlier versions, you should\n        # call \"await cursor.next()\" in a loop.\n        cursor = await marvel_heroes.run(connection)\n        async for hero in cursor:\n            print(hero['name'])\n    # The `with` block performs `await connection.close(noreply_wait=False)`.\n\nr.set_loop_type('asyncio')\n\n# \"asyncio.run\" was added in Python 3.7.  In earlier versions, you\n# might try asyncio.get_event_loop().run_until_complete(main()).\nasyncio.run(main())\n```\n\n### Gevent mode\n\n```python\nimport gevent\nfrom rethinkdb import r\n\ndef main():\n    r.set_loop_type('gevent')\n    connection = r.connect(db='test')\n\n    r.table_create('marvel').run(connection)\n\n    marvel_heroes = r.table('marvel')\n    marvel_heroes.insert({\n        'id': 1,\n        'name': 'Iron Man',\n        'first_appearance': 'Tales of Suspense #39'\n    }).run(connection)\n\n    for hero in marvel_heroes.run(connection):\n        print(hero['name'])\n\ngevent.joinall([gevent.spawn(main)])\n```\n\n### Tornado mode\nTornado mode is compatible with Tornado \u003c 5.0.0. Tornado 5 is not supported.\n\n```python\nfrom rethinkdb import r\nfrom tornado import gen\nfrom tornado.ioloop import IOLoop\n\n@gen.coroutine\ndef main():\n    r.set_loop_type('tornado')\n    connection = yield r.connect(db='test')\n\n    yield r.table_create('marvel').run(connection)\n\n    marvel_heroes = r.table('marvel')\n    yield marvel_heroes.insert({\n        'id': 1,\n        'name': 'Iron Man',\n        'first_appearance': 'Tales of Suspense #39'\n    }).run(connection)\n\n    cursor = yield marvel_heroes.run(connection)\n    while (yield cursor.fetch_next()):\n        hero = yield cursor.next()\n        print(hero['name'])\n\nIOLoop.current().run_sync(main)\n```\n\n### Trio mode\n\n```python\nfrom rethinkdb import r\nimport trio\n\nasync def main():\n    r.set_loop_type('trio')\n    async with trio.open_nursery() as nursery:\n        async with r.open(db='test', nursery=nursery) as conn:\n            await r.table_create('marvel').run(conn)\n            marvel_heroes = r.table('marvel')\n            await marvel_heroes.insert({\n                'id': 1,\n                'name': 'Iron Man',\n                'first_appearance': 'Tales of Suspense #39'\n            }).run(conn)\n\n            # \"async for\" is supported in Python ≥ 3.6. In earlier versions, you should\n            # call \"await cursor.next()\" in a loop.\n            cursor = await marvel_heroes.run(conn)\n            async with cursor:\n                async for hero in cursor:\n                    print(hero['name'])\n\ntrio.run(main)\n```\n\nThe Trio mode also supports a database connection pool. You can modify the example above\nas follows:\n\n```python\ndb_pool = r.ConnectionPool(db='test', nursery=nursery)\nasync with db_pool.connection() as conn:\n    ...\nawait db_pool.close()\n```\n\n### Twisted mode\n\n```python\nfrom rethinkdb import r\nfrom twisted.internet import reactor, defer\n\n@defer.inlineCallbacks\ndef main():\n    r.set_loop_type('twisted')\n    connection = yield r.connect(db='test')\n\n    yield r.table_create('marvel').run(connection)\n\n    marvel_heroes = r.table('marvel')\n    yield marvel_heroes.insert({\n        'id': 1,\n        'name': 'Iron Man',\n        'first_appearance': 'Tales of Suspense #39'\n    }).run(connection)\n\n    cursor = yield marvel_heroes.run(connection)\n    while (yield cursor.fetch_next()):\n        hero = yield cursor.next()\n        print(hero['name'])\n\nmain().addCallback(lambda d: print(\"stopping\") or reactor.stop())\nreactor.run()\n```\n\n## Misc\nTo help the migration from rethinkdb\u003c2.4 we introduced a shortcut which can easily replace the old `import rethinkdb as r` import with `from rethinkdb import r`.\n\n## Run tests\nIn the `Makefile` you can find three different test commands: `test-unit`, `test-integration` and `test-remote`. As RethinkDB has dropped the support of Windows, we would like to ensure that those of us who are using Windows for development can still contribute. Because of this, we support running integration tests against Digital Ocean Droplets as well.\n\nBefore you run any test, make sure that you install the requirements.\n```bash\n$ pip install -r requirements.txt\n$ make prepare\n```\n\n### Running unit tests\n```bash\n$ make test-unit\n```\n\n### Running integration tests\n*To run integration tests locally, make sure you intstalled RethinkDB*\n```bash\n$ make test-integration\n```\n\n### Running remote integration tests\n*To run the remote tests, you need to have a Digital Ocean account and an API key.*\n\nRemote test will create a new temporary SSH key and a Droplet for you until the tests are finished.\n\n**Available environment variables**\n\n| Variable name | Default value |\n|---------------|---------------|\n| DO_TOKEN      | N/A           |\n| DO_SIZE       | 512MB         |\n| DO_REGION     | sfo2          |\n\n```bash\n$ pip install paramiko python-digitalocean\n$ export DO_TOKEN=\u003cYOUR_TOKEN\u003e\n$ make test-remote\n```\n\n## Contributing\nHurray! You reached this section which means, that you would like to contribute. Please read our contributing guide lines and feel free to open a pull request.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frethinkdb%2Frethinkdb-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frethinkdb%2Frethinkdb-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frethinkdb%2Frethinkdb-python/lists"}