PageRenderTime 26ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/doc/build/intro.rst

https://bitbucket.org/zzzeek/sqlalchemy
ReStructuredText | 206 lines | 145 code | 61 blank | 0 comment | 0 complexity | d343b8f8c974fc95f62eee7313e3e41e MD5 | raw file
  1. .. _overview_toplevel:
  2. .. _overview:
  3. ========
  4. Overview
  5. ========
  6. The SQLAlchemy SQL Toolkit and Object Relational Mapper
  7. is a comprehensive set of tools for working with
  8. databases and Python. It has several distinct areas of
  9. functionality which can be used individually or combined
  10. together. Its major components are illustrated below,
  11. with component dependencies organized into layers:
  12. .. image:: sqla_arch_small.png
  13. Above, the two most significant front-facing portions of
  14. SQLAlchemy are the **Object Relational Mapper (ORM)** and the
  15. **Core**.
  16. Core contains the breadth of SQLAlchemy's SQL and database
  17. integration and description services, the most prominent part of this
  18. being the **SQL Expression Language**.
  19. The SQL Expression Language is a toolkit all its own, independent of the ORM
  20. package, which provides a system of constructing SQL expressions represented by
  21. composable objects, which can then be "executed" against a target database
  22. within the scope of a specific transaction, returning a result set.
  23. Inserts, updates and deletes (i.e. :term:`DML`) are achieved by passing
  24. SQL expression objects representing these statements along with dictionaries
  25. that represent parameters to be used with each statement.
  26. The ORM builds upon Core to provide a means of working with a domain object
  27. model mapped to a database schema. When using the ORM, SQL statements are
  28. constructed in mostly the same way as when using Core, however the task of DML,
  29. which here refers to the persistence of business objects in a database, is
  30. automated using a pattern called :term:`unit of work`, which translates changes
  31. in state against mutable objects into INSERT, UPDATE and DELETE constructs
  32. which are then invoked in terms of those objects. SELECT statements are also
  33. augmented by ORM-specific automations and object-centric querying capabilities.
  34. Whereas working with Core and the SQL Expression language presents a
  35. schema-centric view of the database, along with a programming paradigm that is
  36. oriented around immutability, the ORM builds on top of this a domain-centric
  37. view of the database with a programming paradigm that is more explcitly
  38. object-oriented and reliant upon mutability. Since a relational database is
  39. itself a mutable service, the difference is that Core/SQL Expression language
  40. is command oriented whereas the ORM is state oriented.
  41. .. _doc_overview:
  42. Documentation Overview
  43. ======================
  44. The documentation is separated into four sections:
  45. * :ref:`unified_tutorial` - this all-new tutorial for the 1.4/2.0 series of
  46. SQLAlchemy introduces the entire library holistically, starting from a
  47. description of Core and working more and more towards ORM-specific concepts.
  48. New users, as well as users coming from :term:`1.x style`, who wish to work
  49. in :term:`2.0 style` should start here.
  50. * :ref:`orm_toplevel` - In this section, reference documentation for the ORM is
  51. presented; this section also includes the now-legacy
  52. :ref:`ormtutorial_toplevel`.
  53. * :ref:`core_toplevel` - Here, reference documentation for
  54. everything else within Core is presented; section also includes the legacy
  55. :ref:`sqlexpression_toplevel`. SQLAlchemy engine, connection, and pooling
  56. services are also described here.
  57. * :ref:`dialect_toplevel` - Provides reference documentation
  58. for all :term:`dialect` implementations, including :term:`DBAPI` specifics.
  59. Code Examples
  60. =============
  61. Working code examples, mostly regarding the ORM, are included in the
  62. SQLAlchemy distribution. A description of all the included example
  63. applications is at :ref:`examples_toplevel`.
  64. There is also a wide variety of examples involving both core SQLAlchemy
  65. constructs as well as the ORM on the wiki. See
  66. `Theatrum Chemicum <https://www.sqlalchemy.org/trac/wiki/UsageRecipes>`_.
  67. .. _installation:
  68. Installation Guide
  69. ==================
  70. Supported Platforms
  71. -------------------
  72. SQLAlchemy supports the following platforms:
  73. * cPython 3.7 and higher
  74. * Python-3 compatible versions of `PyPy <http://pypy.org/>`_
  75. .. versionchanged:: 2.0
  76. SQLAlchemy now targets Python 3.7 and above.
  77. AsyncIO Support
  78. ----------------
  79. SQLAlchemy's ``asyncio`` support depends upon the
  80. `greenlet <https://pypi.org/project/greenlet/>`_ project. This dependency
  81. will be installed by default on common machine platforms, however is not
  82. supported on every architecture and also may not install by default on
  83. less common architectures. See the section :ref:`asyncio_install` for
  84. additional details on ensuring asyncio support is present.
  85. Supported Installation Methods
  86. -------------------------------
  87. SQLAlchemy installation is via standard Python methodologies that are
  88. based on `setuptools <https://pypi.org/project/setuptools/>`_, either
  89. by referring to ``setup.py`` directly or by using
  90. `pip <https://pypi.org/project/pip/>`_ or other setuptools-compatible
  91. approaches.
  92. Install via pip
  93. ---------------
  94. When ``pip`` is available, the distribution can be
  95. downloaded from PyPI and installed in one step::
  96. pip install SQLAlchemy
  97. This command will download the latest **released** version of SQLAlchemy from the `Python
  98. Cheese Shop <https://pypi.org/project/SQLAlchemy>`_ and install it to your system.
  99. In order to install the latest **prerelease** version, such as ``2.0.0b1``,
  100. pip requires that the ``--pre`` flag be used::
  101. pip install --pre SQLAlchemy
  102. Where above, if the most recent version is a prerelease, it will be installed
  103. instead of the latest released version.
  104. Installing using setup.py
  105. ----------------------------------
  106. Otherwise, you can install from the distribution using the ``setup.py`` script::
  107. python setup.py install
  108. .. _c_extensions:
  109. Installing the C Extensions
  110. ----------------------------------
  111. SQLAlchemy includes C extensions which provide an extra speed boost for
  112. dealing with result sets. The extensions are supported on both the 2.xx
  113. and 3.xx series of cPython.
  114. ``setup.py`` will automatically build the extensions if an appropriate platform is
  115. detected. If the build of the C extensions fails due to a missing compiler or
  116. other issue, the setup process will output a warning message and re-run the
  117. build without the C extensions upon completion, reporting final status.
  118. To run the build/install without even attempting to compile the C extensions,
  119. the ``DISABLE_SQLALCHEMY_CEXT`` environment variable may be specified. The
  120. use case for this is either for special testing circumstances, or in the rare
  121. case of compatibility/build issues not overcome by the usual "rebuild"
  122. mechanism::
  123. export DISABLE_SQLALCHEMY_CEXT=1; python setup.py install
  124. .. versionchanged:: 1.1 The legacy ``--without-cextensions`` flag has been
  125. removed from the installer as it relies on deprecated features of
  126. setuptools.
  127. Installing a Database API
  128. ----------------------------------
  129. SQLAlchemy is designed to operate with a :term:`DBAPI` implementation built for a
  130. particular database, and includes support for the most popular databases.
  131. The individual database sections in :doc:`/dialects/index` enumerate
  132. the available DBAPIs for each database, including external links.
  133. Checking the Installed SQLAlchemy Version
  134. ------------------------------------------
  135. This documentation covers SQLAlchemy version 2.0. If you're working on a
  136. system that already has SQLAlchemy installed, check the version from your
  137. Python prompt like this:
  138. .. sourcecode:: python+sql
  139. >>> import sqlalchemy
  140. >>> sqlalchemy.__version__ # doctest: +SKIP
  141. 2.0.0
  142. .. _migration:
  143. 1.x to 2.0 Migration
  144. =====================
  145. Notes on the new API released in SQLAlchemy 2.0 is available here at :doc:`changelog/migration_20`.