Intégrer Spanner à l'ORM SQLAlchemy (dialecte GoogleSQL)
Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
SQLAlchemy est une boîte à outils SQL pour Python et un mappeur objet-relationnel.
Le dialecte Spanner pour SQLAlchemy permet aux utilisateurs de SQLAlchemy d'utiliser des bases de données Spanner. Le dialecte est basé sur l'API Spanner, conçue conformément à PEP-249 et compatible avec les versions SQLAlchemy comprises entre 1.1.13 et 1.3.23, ainsi qu'avec 2.0.
Configurer le dialecte Spanner pour SQLAlchemy
Pour configurer le dialecte Spanner pour SQLAlchemy dans votre application, installez sqlalchemy-spanner package.
pip3installsqlalchemy-spanner
Vous pouvez également installer à partir de la source.
Pour l'authentification du dialecte Spanner pour SQLAlchemy, fournissez l'emplacement du fichier d'identifiants JSON du compte de service dans la variable d'environnement GOOGLE_APPLICATION_CREDENTIALS. Sinon, le dialecte peut également utiliser les identifiants par défaut définis dans l'application gcloud CLI.
Utiliser le dialecte Spanner pour SQLAlchemy
Pour en savoir plus sur les fonctionnalités disponibles, les limites du dialecte, les recommandations d'utilisation du dialecte et les exemples de code, veuillez consulter la documentation de référence sur GitHub.
Étape suivante
Consultez des exemples de code pour savoir comment utiliser le dialecte Spanner pour SQLAlchemy.
Affichez le dépôt du dialecte Spanner pour SQLAlchemy sur GitHub.
Ouvrez une demande GitHub pour signaler un bug ou poser une question sur le dialecte Spanner pour SQLAlchemy.
Obtenez davantage d'informations concernant les identifiants d'autorisation et d'authentification sur la page Premiers pas avec l'authentification.
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/09/05 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/09/05 (UTC)."],[],[],null,["# Integrate Spanner with SQLAlchemy ORM (GoogleSQL dialect)\n\n[SQLAlchemy](https://www.sqlalchemy.org/) is a Python SQL toolkit and Object\nRelational Mapper.\n\nThe [Spanner dialect for SQLAlchemy](https://github.com/googleapis/python-spanner-sqlalchemy) lets\nSQLAlchemy users to use Spanner databases. The dialect is built on top\nof the [Spanner API](https://github.com/googleapis/python-spanner/tree/main/google/cloud/spanner_dbapi), which is designed in\naccordance with [PEP-249](https://www.python.org/dev/peps/pep-0249/), and is compatible with\nSQLAlchemy versions between [1.1.13](https://pypi.org/project/SQLAlchemy/1.1.13/) and\n[1.3.23](https://pypi.org/project/SQLAlchemy/1.3.23/), and [2.0](https://pypi.org/project/SQLAlchemy/2.0.0/).\n\n\n| **PostgreSQL interface note:** To use [PostgreSQL interface for Spanner](/spanner/docs/postgresql-interface) with SQLAlchemy, see [Integrate Spanner with SQLAlchemy 2 ORM (PostgreSQL-dialect)](/spanner/docs/use-sqlalchemy-pg).\n\n\u003cbr /\u003e\n\nSet up the Spanner dialect for SQLAlchemy\n-----------------------------------------\n\nTo set up the Spanner dialect for SQLAlchemy in your application, install the\n[`sqlalchemy-spanner package`](https://pypi.org/project/sqlalchemy-spanner/). \n\n pip3 install sqlalchemy-spanner\n\nAlternatively, you can install from source. \n\n git clone https://github.com/googleapis/python-spanner-sqlalchemy.git\n cd python-spanner-sqlalchemy\n python setup.py install\n\nAs authentication for the Spanner dialect for SQLAlchemy, provide the [service account\nJSON credentials](/docs/authentication/getting-started) file location in the\n`GOOGLE_APPLICATION_CREDENTIALS` environment variable. Otherwise, the dialect\ncan also use the default credentials set in the gcloud CLI\napplication.\n\nUse the Spanner dialect for SQLAlchemy\n--------------------------------------\n\nFor more information about the available features, limitations of the dialect,\nrecommendations on how to use the dialect, and for code samples, please consult\nthe [reference documentation](https://github.com/googleapis/python-spanner-sqlalchemy#readme) on\nGitHub.\n\nWhat's next\n-----------\n\n- Check out the [code examples](https://github.com/googleapis/python-spanner-sqlalchemy/blob/main/samples/snippets.py) on how to use the Spanner dialect for SQLAlchemy.\n- View the repository for the Spanner dialect for SQLAlchemy on [GitHub](https://github.com/googleapis/python-spanner-sqlalchemy).\n- File a [GitHub issue](https://github.com/googleapis/python-spanner-sqlalchemy/issues) to report a bug or ask a question about the Spanner dialect for SQLAlchemy.\n- Learn more about [SQLAlchemy](https://www.sqlalchemy.org/).\n- Learn more about [PyPI](https://pypi.org/).\n- Learn about authorization and authentication credentials in [Getting started with authentication](/docs/authentication/getting-started)."]]