{"id":22286029,"url":"https://github.com/thegeorgeous/flask-cqlalchemy","last_synced_at":"2025-07-28T22:31:28.708Z","repository":{"id":33628836,"uuid":"37281136","full_name":"thegeorgeous/flask-cqlalchemy","owner":"thegeorgeous","description":"Flask-CQLAlchemy handles connections to Cassandra clusters and provides a Flask-SQLAlchemy like interface to declare models and their columns in a Flask app","archived":false,"fork":false,"pushed_at":"2022-01-30T19:45:56.000Z","size":140,"stargazers_count":42,"open_issues_count":4,"forks_count":20,"subscribers_count":10,"default_branch":"master","last_synced_at":"2023-08-06T14:36:40.760Z","etag":null,"topics":["cassandra","cassandra-cluster","cqlengine","flask","flask-extensions","python"],"latest_commit_sha":null,"homepage":"http://thegeorgeous.com/flask-cqlalchemy/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thegeorgeous.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":"2015-06-11T19:20:06.000Z","updated_at":"2023-02-28T17:06:23.000Z","dependencies_parsed_at":"2022-08-17T21:20:18.170Z","dependency_job_id":null,"html_url":"https://github.com/thegeorgeous/flask-cqlalchemy","commit_stats":null,"previous_names":[],"tags_count":10,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thegeorgeous%2Fflask-cqlalchemy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thegeorgeous%2Fflask-cqlalchemy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thegeorgeous%2Fflask-cqlalchemy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thegeorgeous%2Fflask-cqlalchemy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thegeorgeous","download_url":"https://codeload.github.com/thegeorgeous/flask-cqlalchemy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227961860,"owners_count":17847836,"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":["cassandra","cassandra-cluster","cqlengine","flask","flask-extensions","python"],"created_at":"2024-12-03T16:54:26.982Z","updated_at":"2024-12-03T16:54:27.726Z","avatar_url":"https://github.com/thegeorgeous.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Flask-CQLAlchemy\n\n[![Latest Version](https://img.shields.io/pypi/v/flask-cqlalchemy.svg)](https://pypi.python.org/pypi/Flask-CQLAlchemy)\n[![License](https://img.shields.io/pypi/l/Flask-CQLAlchemy.svg)](https://pypi.python.org/pypi/Flask-CQLAlchemy)\n[![Python Versions](https://img.shields.io/pypi/pyversions/flask-cqlalchemy.svg)](https://pypi.python.org/pypi/Flask-CQLAlchemy)\n[![CI Build and Test](https://github.com/thegeorgeous/flask-cqlalchemy/actions/workflows/ci-build-test.yml/badge.svg?branch=master)](https://github.com/thegeorgeous/flask-cqlalchemy/actions/workflows/ci-build-test.yml)\n[![Code Climate](https://codeclimate.com/github/thegeorgeous/flask-cqlalchemy/badges/gpa.svg)](https://codeclimate.com/github/thegeorgeous/flask-cqlalchemy)\n\n\nFlask-CQLAlchemy handles connections to Cassandra clusters and gives a unified easier way to declare models and\ntheir columns.\n\n## Installation\n```shell\n$ pip install flask-cqlalchemy\n```\n\n## Dependencies\nAs Flask-CQLAlchemy depends only on the `cassandra-driver`. It is assumed that you already have `Flask` installed.\n\nFlask-CQLAlchemy has been tested with all versions of the `cassandra-driver\u003e=3.22.0` and Cassandra 3.0.25, 3.11.11,\n4.x. All previous versions and configurations are deprecated. Used to be reported that plugin worked with\n`cassandra-driver\u003e=2.5`, we can not guarantee proper work of older configurations so use on your own. Some versions of\n`cassandra-driver` can be incompatible with some versions of Cassandra itself either. \n\nIf you have problems using the plugin, try updating to the latest patch version of the minor version you are using.\n\n## Example\n\n```python\n# example_app.py\nimport uuid\nfrom flask import Flask\nfrom flask_cqlalchemy import CQLAlchemy\n\napp = Flask(__name__)\napp.config['CASSANDRA_HOSTS'] = ['127.0.0.1']\napp.config['CASSANDRA_KEYSPACE'] = \"cqlengine\"\ndb = CQLAlchemy(app)\n\n\nclass User(db.Model):\n    uid = db.columns.UUID(primary_key=True, default=uuid.uuid4)\n    username = db.columns.Text(required=False)\n```\n\n### User Defined Types\n\n```python\n# example_app_udt.py\nfrom flask import Flask\n\nfrom flask_cqlalchemy import CQLAlchemy\n\napp = Flask(__name__)\napp.config['CASSANDRA_HOSTS'] = ['127.0.0.1']\napp.config['CASSANDRA_KEYSPACE'] = \"cqlengine\"\napp.config['CASSANDRA_SETUP_KWARGS'] = {'protocol_version': 3}\ndb = CQLAlchemy(app)\n\n\nclass Address(db.UserType):\n    street = db.columns.Text()\n    zipcode = db.columns.Integer()\n\n\nclass Users(db.Model):\n    __keyspace__ = 'cqlengine'\n    name = db.columns.Text(primary_key=True)\n    addr = db.columns.UserDefinedType(Address)\n```\n\n## Usage\nEnter in Python Interpreter:\n```python\n\u003e\u003e\u003e from example_app import db, User\n\u003e\u003e\u003e db.sync_db()\n\u003e\u003e\u003e user1 = User.create(username='John Doe')\n\u003e\u003e\u003e user1\nUser(example_id=UUID('f94b6156-2964-4d46-919c-d6e4abcb9ef1'), username='John Doe')\n```\n\n### User Defined Types\n```python\n\u003e\u003e\u003e from example_app_udt import db, Address, Users\n\u003e\u003e\u003e db.sync_db()\n\u003e\u003e\u003e user_address = Address(street=\"Easy Street, 12\", zipcode=12345)\n\u003e\u003e\u003e user = Users(name='John Appleseed', addr=user_address)\n\u003e\u003e\u003e user\nUsers(name='John Appleseed', addr=\u003cexample_app_udt.Address object at 0x10fe56070\u003e)\n\u003e\u003e\u003e user.addr\n\u003cexample_app_udt.Address object at 0x10fe56070\u003e\n\u003e\u003e\u003e user.addr.street\n'Easy Street, 12'\n\u003e\u003e\u003e user.addr.zipcode\n12345\n```\n\nFor a complete list of available methods refer to the\n[cassandra.cqlengine.models documentation](https://docs.datastax.com/en/developer/python-driver/latest/api/cassandra/cqlengine/models/).\n\n## Configuration Options\n`CQLAlchemy` object provides following the options available for the\n[cqlengine `connection.setup()`](https://docs.datastax.com/en/developer/python-driver/latest/api/cassandra/cqlengine/connection/):\n\n* `CASSANDRA_HOSTS` — A `list` of hosts\n* `CASSANDRA_KEYSPACE` — The default keyspace name to use\n* `CASSANDRA_CONSISTENCY` — The global default `ConsistencyLevel`, default is the driver's\n  [`Session.default_consistency_level`](https://docs.datastax.com/en/developer/python-driver/latest/api/cassandra/#cassandra.ConsistencyLevel)\n* `CASSANDRA_LAZY_CONNECT` — `True` if should not connect until first use, default is `False`\n* `CASSANDRA_RETRY_CONNECT` — `True` if we should retry to connect even if there was a connection failure initially,\n  default is `False`\n* `CASSANDRA_SETUP_KWARGS` — Pass-through keyword arguments for `Cluster()`\n\n## API\n`CQLAlchemy` object provides some helper methods for Cassandra database management:\n\n* `sync_db()` — Creates/Syncs all the tables corresponding to the models declared in the application.\n* `set_keyspace()` — Sets the keyspace for a session. Keyspaces once set will remain the default keyspace for the\n  duration of the session. If the change is temporary, it must be reverted back to the default keyspace explicitly.\n\n## Contributing\nFound a bug? Need a feature? Open it in [issues](https://github.com/thegeorgeous/flask-cqlalchemy/issues), or even\nbetter, open a [PR](https://github.com/thegeorgeous/flask-cqlalchemy/pulls). Please include tests in the PR.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthegeorgeous%2Fflask-cqlalchemy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthegeorgeous%2Fflask-cqlalchemy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthegeorgeous%2Fflask-cqlalchemy/lists"}