Skip to content

Commit 21c9e00

Browse files
authored
Prep spanner docs for repo split. (#5938)
- Move docs from 'docs/spanner' into 'spanner/docs' and leave symlink. - Harmonize / DRY 'spanner/README.rst' and 'spanner/docs/index.rst'. - Ensure that docs still build from top-level. Toward #5912.
1 parent bcc9837 commit 21c9e00

28 files changed

Lines changed: 1993 additions & 40 deletions

README.rst

Lines changed: 63 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,82 @@
11
Python Client for Cloud Spanner
22
===============================
33

4-
Python idiomatic client for `Cloud Spanner`_.
4+
|pypi| |versions|
55

6-
.. _Cloud Spanner: https://cloud.google.com/spanner/
6+
`Cloud Spanner`_ is the world's first fully managed relational database service
7+
to offer both strong consistency and horizontal scalability for
8+
mission-critical online transaction processing (OLTP) applications. With Cloud
9+
Spanner you enjoy all the traditional benefits of a relational database; but
10+
unlike any other relational database service, Cloud Spanner scales horizontally
11+
to hundreds or thousands of servers to handle the biggest transactional
12+
workloads.
713

8-
|pypi| |versions|
914

10-
- `Documentation`_
15+
- `Client Library Documentation`_
16+
- `Product Documentation`_
1117

12-
.. _Documentation: https://googlecloudplatform.github.io/google-cloud-python/latest/spanner/usage.html
18+
19+
.. |pypi| image:: https://img.shields.io/pypi/v/google-cloud-spanner.svg
20+
:target: https://pypi.org/project/google-cloud-spanner/
21+
.. |versions| image:: https://img.shields.io/pypi/pyversions/google-cloud-spanner.svg
22+
:target: https://pypi.org/project/google-cloud-spanner/
23+
.. _Cloud Spanner: https://cloud.google.com/spanner/
24+
.. _Client Library Documentation: https://googlecloudplatform.github.io/google-cloud-python/latest/spanner/index.html
25+
.. _Product Documentation: https://cloud.google.com/spanner/docs
1326

1427
Quick Start
1528
-----------
1629

17-
.. code-block:: console
30+
In order to use this library, you first need to go through the following steps:
1831

19-
$ pip install --upgrade google-cloud-spanner
32+
1. `Select or create a Cloud Platform project.`_
33+
2. `Enable billing for your project.`_
34+
3. `Enable the Google Cloud Datastore API.`_
35+
4. `Setup Authentication.`_
2036

21-
For more information on setting up your Python development environment,
22-
such as installing ``pip`` and ``virtualenv`` on your system, please refer
23-
to `Python Development Environment Setup Guide`_ for Google Cloud Platform.
37+
.. _Select or create a Cloud Platform project.: https://console.cloud.google.com/project
38+
.. _Enable billing for your project.: https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project
39+
.. _Enable the Google Cloud Datastore API.: https://cloud.google.com/datastore
40+
.. _Setup Authentication.: https://googlecloudplatform.github.io/google-cloud-python/latest/core/auth.html
2441

25-
.. _Python Development Environment Setup Guide: https://cloud.google.com/python/setup
42+
Installation
43+
~~~~~~~~~~~~
2644

45+
Install this library in a `virtualenv`_ using pip. `virtualenv`_ is a tool to
46+
create isolated Python environments. The basic problem it addresses is one of
47+
dependencies and versions, and indirectly permissions.
2748

28-
Authentication
29-
--------------
49+
With `virtualenv`_, it's possible to install this library without needing system
50+
install permissions, and without clashing with the installed system
51+
dependencies.
3052

31-
With ``google-cloud-python`` we try to make authentication as painless as
32-
possible. Check out the `Authentication section`_ in our documentation to
33-
learn more. You may also find the `authentication document`_ shared by all
34-
the ``google-cloud-*`` libraries to be helpful.
53+
.. _`virtualenv`: https://virtualenv.pypa.io/en/latest/
3554

36-
.. _Authentication section: https://google-cloud-python.readthedocs.io/en/latest/core/auth.html
37-
.. _authentication document: https://github.com/GoogleCloudPlatform/google-cloud-common/tree/master/authentication
3855

56+
Mac/Linux
57+
^^^^^^^^^
3958

40-
Using the API
41-
-------------
59+
.. code-block:: console
4260
43-
Cloud Spanner is the world’s first fully managed relational database service
44-
to offer both strong consistency and horizontal scalability for
45-
mission-critical online transaction processing (OLTP) applications. With Cloud
46-
Spanner you enjoy all the traditional benefits of a relational database; but
47-
unlike any other relational database service, Cloud Spanner scales
48-
horizontally to hundreds or thousands of servers to handle the biggest
49-
transactional workloads. (`About Cloud Spanner`_)
61+
pip install virtualenv
62+
virtualenv <your-env>
63+
source <your-env>/bin/activate
64+
<your-env>/bin/pip install google-cloud-datastore
65+
66+
67+
Windows
68+
^^^^^^^
5069

51-
.. _About Cloud Spanner: https://cloud.google.com/spanner/
70+
.. code-block:: console
71+
72+
pip install virtualenv
73+
virtualenv <your-env>
74+
<your-env>\Scripts\activate
75+
<your-env>\Scripts\pip.exe install google-cloud-datastore
76+
77+
78+
Example Usage
79+
-------------
5280

5381

5482
Executing Arbitrary SQL in a Transaction
@@ -152,15 +180,10 @@ if any of the records does not already exist.
152180
)
153181
154182
155-
Learn More
156-
----------
157-
158-
See the ``google-cloud-python`` API `Cloud Spanner documentation`_ to learn how
159-
to connect to Cloud Spanner using this Client Library.
183+
Next Steps
184+
~~~~~~~~~~
160185

161-
.. _Cloud Spanner documentation: https://googlecloudplatform.github.io/google-cloud-python/latest/spanner/usage.html
162-
163-
.. |pypi| image:: https://img.shields.io/pypi/v/google-cloud-spanner.svg
164-
:target: https://pypi.org/project/google-cloud-spanner/
165-
.. |versions| image:: https://img.shields.io/pypi/pyversions/google-cloud-spanner.svg
166-
:target: https://pypi.org/project/google-cloud-spanner/
186+
- See the `Client Library Documentation`_ to learn how to connect to Cloud
187+
Spanner using this Client Library.
188+
- Read the `Product documentation`_ to learn
189+
more about the product and see How-to Guides.
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
Advanced Session Pool Topics
2+
============================
3+
4+
Custom Session Pool Implementations
5+
-----------------------------------
6+
7+
You can supply your own pool implementation, which must satisfy the
8+
contract laid out in
9+
:class:`~google.cloud.spanner.pool.AbstractSessionPool`:
10+
11+
.. code-block:: python
12+
13+
from google.cloud.spanner.pool import AbstractSessionPool
14+
15+
class MyCustomPool(AbstractSessionPool):
16+
17+
def __init__(self, custom_param):
18+
super(MyCustomPool, self).__init__()
19+
self.custom_param = custom_param
20+
21+
def bind(self, database):
22+
...
23+
24+
def get(self, read_only=False):
25+
...
26+
27+
def put(self, session, discard_if_full=True):
28+
...
29+
30+
pool = MyCustomPool(custom_param=42)
31+
database = instance.database(DATABASE_NAME, pool=pool)
32+
33+
Lowering latency for read / query operations
34+
--------------------------------------------
35+
36+
Some applications may need to minimize latency for read operations, including
37+
particularly the overhead of making an API request to create or refresh a
38+
session. :class:`~google.cloud.spanner.pool.PingingPool` is designed for such
39+
applications, which need to configure a background thread to do the work of
40+
keeping the sessions fresh.
41+
42+
Create an instance of :class:`~google.cloud.spanner.pool.PingingPool`:
43+
44+
.. code-block:: python
45+
46+
from google.cloud.spanner import Client
47+
from google.cloud.spanner.pool import PingingPool
48+
49+
client = Client()
50+
instance = client.instance(INSTANCE_NAME)
51+
pool = PingingPool(size=10, default_timeout=5, ping_interval=300)
52+
database = instance.database(DATABASE_NAME, pool=pool)
53+
54+
Set up a background thread to ping the pool's session, keeping them
55+
from becoming stale:
56+
57+
.. code-block:: python
58+
59+
import threading
60+
61+
background = threading.Thread(target=pool.ping, name='ping-pool')
62+
background.daemon = True
63+
background.start()
64+
65+
Lowering latency for mixed read-write operations
66+
------------------------------------------------
67+
68+
Some applications may need to minimize latency for read write operations,
69+
including particularly the overhead of making an API request to create or
70+
refresh a session or to begin a session's transaction.
71+
:class:`~google.cloud.spanner.pool.TransactionPingingPool` is designed for
72+
such applications, which need to configure a background thread to do the work
73+
of keeping the sessions fresh and starting their transactions after use.
74+
75+
Create an instance of
76+
:class:`~google.cloud.spanner.pool.TransactionPingingPool`:
77+
78+
.. code-block:: python
79+
80+
from google.cloud.spanner import Client
81+
from google.cloud.spanner.pool import TransactionPingingPool
82+
83+
client = Client()
84+
instance = client.instance(INSTANCE_NAME)
85+
pool = TransactionPingingPool(size=10, default_timeout=5, ping_interval=300)
86+
database = instance.database(DATABASE_NAME, pool=pool)
87+
88+
Set up a background thread to ping the pool's session, keeping them
89+
from becoming stale, and ensuring that each session has a new transaction
90+
started before it is used:
91+
92+
.. code-block:: python
93+
94+
import threading
95+
96+
background = threading.Thread(target=pool.ping, name='ping-pool')
97+
background.daemon = True
98+
background.start()

docs/api-reference.rst

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
API Reference
2+
=============
3+
4+
The following classes and methods constitute the Spanner client.
5+
Most likely, you will be interacting almost exclusively with these:
6+
7+
.. toctree::
8+
:maxdepth: 1
9+
10+
client-api
11+
instance-api
12+
database-api
13+
session-api
14+
keyset-api
15+
snapshot-api
16+
batch-api
17+
transaction-api
18+
streamed-api
19+
20+
21+
The classes and methods above depend on the following, lower-level
22+
classes and methods. Documentation for these is provided for completion,
23+
and some advanced use cases may wish to interact with these directly:
24+
25+
.. toctree::
26+
:maxdepth: 1
27+
28+
gapic/v1/api
29+
gapic/v1/types
30+
gapic/v1/admin_database_api
31+
gapic/v1/admin_database_types
32+
gapic/v1/admin_instance_api
33+
gapic/v1/admin_instance_types

docs/batch-api.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Batch API
2+
=========
3+
4+
.. automodule:: google.cloud.spanner_v1.batch
5+
:members:
6+
:show-inheritance:

0 commit comments

Comments
 (0)