{"id":14065623,"url":"https://github.com/altairbow/django-db-connection-pool","last_synced_at":"2025-05-15T09:02:30.321Z","repository":{"id":41176404,"uuid":"164835376","full_name":"altairbow/django-db-connection-pool","owner":"altairbow","description":"Database connection pool component library for Django","archived":false,"fork":false,"pushed_at":"2025-05-05T03:44:39.000Z","size":186,"stargazers_count":228,"open_issues_count":8,"forks_count":25,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-05-05T03:45:39.327Z","etag":null,"topics":["database","database-pool","database-pooling","django","jdbc","mysql","oceanbase","odbc","pool","pooling","postgres","postgresql","python"],"latest_commit_sha":null,"homepage":"https://pypi.python.org/pypi/django-db-connection-pool/","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/altairbow.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-01-09T09:50:42.000Z","updated_at":"2025-05-05T03:14:40.000Z","dependencies_parsed_at":"2023-09-29T07:12:19.386Z","dependency_job_id":"c65b09b7-9326-42d2-a736-3f1ce78c8d27","html_url":"https://github.com/altairbow/django-db-connection-pool","commit_stats":{"total_commits":120,"total_committers":9,"mean_commits":"13.333333333333334","dds":0.125,"last_synced_commit":"147a582034b4f1aac7d06eeab5105b088b057303"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/altairbow%2Fdjango-db-connection-pool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/altairbow%2Fdjango-db-connection-pool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/altairbow%2Fdjango-db-connection-pool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/altairbow%2Fdjango-db-connection-pool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/altairbow","download_url":"https://codeload.github.com/altairbow/django-db-connection-pool/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254310511,"owners_count":22049468,"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":["database","database-pool","database-pooling","django","jdbc","mysql","oceanbase","odbc","pool","pooling","postgres","postgresql","python"],"created_at":"2024-08-13T07:04:35.952Z","updated_at":"2025-05-15T09:02:30.302Z","avatar_url":"https://github.com/altairbow.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# django-db-connection-pool\n\n:star: If this project is helpful to you, please light up the star, Thank you:smile:\n\nMySQL \u0026 Oracle \u0026 PostgreSQL \u0026 JDBC (Oracle, OceanBase) connection pool components for Django,\nBe based on [SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy).\nWorks fine in multiprocessing and multithreading django project.\n\n* [中文版](README_CN.md)\n\n## Quickstart\n\n### Installation\n\nInstall with `pip` with all engines:\n\n```bash\n$ pip install django-db-connection-pool[all]\n```\n\nor select specific engines:\n\n```bash\n$ pip install django-db-connection-pool[mysql,oracle,postgresql,jdbc]\n```\n\nor one of mysql,oracle,postgresql,jdbc\n\n```bash\n$ pip install django-db-connection-pool[oracle]\n```\n\n### Update settings.DATABASES\n\n#### MySQL\n\nchange `django.db.backends.mysql` to `dj_db_conn_pool.backends.mysql`:\n\n```python\nDATABASES = {\n    'default': {\n        'ENGINE': 'dj_db_conn_pool.backends.mysql'\n    }\n}\n```\n\n#### Oracle\n\nchange `django.db.backends.oracle` to `dj_db_conn_pool.backends.oracle`:\n\n```python\nDATABASES = {\n    'default': {\n        'ENGINE': 'dj_db_conn_pool.backends.oracle'\n    }\n}\n```\n\n#### PostgreSQL\n\nchange `django.db.backends.postgresql` to `dj_db_conn_pool.backends.postgresql`:\n\n```python\nDATABASES = {\n    'default': {\n        'ENGINE': 'dj_db_conn_pool.backends.postgresql'\n    }\n}\n```\n\n#### Pool options(optional)\n\nyou can provide additional options to pass to SQLAlchemy's pool creation, key's name is `POOL_OPTIONS`:\n\n```python\nDATABASES = {\n    'default': {\n        'POOL_OPTIONS': {\n            'POOL_SIZE': 10,\n            'MAX_OVERFLOW': 10,\n            'RECYCLE': 24 * 60 * 60\n        }\n    }\n}\n```\n\n`django-db-connection-pool` has more configuration options\nhere: [PoolContainer.pool_default_params](https://github.com/altairbow/django-db-connection-pool/blob/master/dj_db_conn_pool/core/__init__.py#L13-L20)\n\nHere's the explanation of these options(from SQLAlchemy's Doc):\n\n* **pool_size**: The size of the pool to be maintained,\n  defaults to 5. This is the largest number of connections that\n  will be kept persistently in the pool. Note that the pool\n  begins with no connections; once this number of connections\n  is requested, that number of connections will remain.\n  `pool_size` can be set to 0 to indicate no size limit; to\n  disable pooling, use a :class:`~sqlalchemy.pool.NullPool`\n  instead.\n\n* **max_overflow**: The maximum overflow size of the\n  pool. When the number of checked-out connections reaches the\n  size set in pool_size, additional connections will be\n  returned up to this limit. When those additional connections\n  are returned to the pool, they are disconnected and\n  discarded. It follows then that the total number of\n  simultaneous connections the pool will allow is pool_size +\n  `max_overflow`, and the total number of \"sleeping\"\n  connections the pool will allow is pool_size. `max_overflow`\n  can be set to -1 to indicate no overflow limit; no limit\n  will be placed on the total number of concurrent\n  connections. Defaults to 10.\n\n* **recycle**: If set to a value other than -1, number of seconds\n  between connection recycling, which means upon checkout,\n  if this timeout is surpassed the connection will be closed\n  and replaced with a newly opened connection.\n  Defaults to -1.\n\nOr, you can use dj_db_conn_pool.setup to change default arguments(for each pool's creation), before using database pool:\n\n```python\nimport dj_db_conn_pool\n\ndj_db_conn_pool.setup(pool_size=100, max_overflow=50)\n```\n\n#### multiprocessing environment\n\nIn a multiprocessing environment, such as uWSGI, each process will have its own `dj_db_conn_pool.core:pool_container`\nobject,\nIt means that each process has an independent connection pool, for example:\nThe `POOL_OPTIONS` configuration of database `db1` is`{ 'POOL_SIZE': 10, 'MAX_OVERFLOW': 20 }`,\nIf uWSGI starts 8 worker processes, then the total connection pool size of `db1`  is `8 * 10`,\nThe maximum number of connections will not exceed `8 * 10 + 8 * 20`\n\n## JDBC\n\nThanks to [JPype](https://github.com/jpype-project/jpype),\ndjango-db-connection-pool can connect to database by jdbc\n\n### Usage\n\n#### Set Java runtime environment\n\n```bash\nexport JAVA_HOME=$PATH_TO_JRE;\nexport CLASSPATH=$PATH_RO_JDBC_DRIVER_JAR\n```\n\n#### Update settings.DATABASES\n\n##### Oracle\n\nchange `django.db.backends.oracle` to `dj_db_conn_pool.backends.jdbc.oracle`:\n\n```python\nDATABASES = {\n    'default': {\n        'ENGINE': 'dj_db_conn_pool.backends.jdbc.oracle'\n    }\n}\n```\n\n##### OceanBase\n\nuse `dj_db_conn_pool.backends.jdbc.oceanbase`:\n\n```python\nDATABASES = {\n    'default': {\n        'ENGINE': 'dj_db_conn_pool.backends.jdbc.oceanbase'\n    }\n}\n```\n\n### Performing raw SQL queries\n\nJust like django's built-in backends, all JDBC backends support named parameters in raw SQL queries,\nyou can execute raw sql queries like this:\n\n```python\nfrom django.db import connections\n\nwith connections[\"default\"].cursor() as cursor:\n    cursor.execute('select name, phone from users where name = %(name)s', params={\"name\": \"Altair\"})\n    result = cursor.fetchall()\n```\n\n### Acknowledgments\n- Thanks to all friends who provided PR and suggestions !\n- Thanks to [JetBrains](https://www.jetbrains.com/?from=django-db-connection-pool) for providing development tools for django-db-connection-pool !\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faltairbow%2Fdjango-db-connection-pool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faltairbow%2Fdjango-db-connection-pool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faltairbow%2Fdjango-db-connection-pool/lists"}