@@ -82,10 +82,6 @@ Guidelines](#testing-guidelines) are covered separately below.
82
82
83
83
### Folder Location
84
84
85
- Samples that primarily show the use of one client library should be placed in
86
- the client library repository ` googleapis/python-{api} ` . Other samples should be
87
- placed in this repository ` python-docs-samples ` .
88
-
89
85
** Library repositories:** Each sample should be in a folder under the top-level
90
86
samples folder ` samples ` in the client library repository. See the
91
87
[ Text-to-Speech
@@ -108,12 +104,6 @@ folder, and App Engine Flex samples are under the
108
104
[ appengine/flexible] ( https://github.com/GoogleCloudPlatform/python-docs-samples/tree/main/appengine/flexible )
109
105
folder.
110
106
111
- If your sample is a set of discrete code snippets that each demonstrate a single
112
- operation, these should be grouped into a ` snippets ` folder. For example, see
113
- the snippets in the
114
- [ bigtable/snippets/writes] ( https://github.com/googleapis/python-bigtable/tree/main/samples/snippets/writes )
115
- folder.
116
-
117
107
If your sample is a quickstart — intended to demonstrate how to quickly get
118
108
started with using a service or API — it should be in a _ quickstart_ folder.
119
109
@@ -274,11 +264,12 @@ task_from_dict = {
274
264
275
265
### Functions and Classes
276
266
277
- Very few samples will require authoring classes. Prefer functions whenever
278
- possible. See [ this video] ( https://www.youtube.com/watch?v=o9pEzgHorH0 ) for some
279
- insight into why classes aren't as necessary as you might think in Python.
280
- Classes also introduce cognitive load. If you do write a class in a sample, be
281
- prepared to justify its existence during code review.
267
+ Prefer functions over classes whenever possible.
268
+
269
+ See [ this video] ( https://www.youtube.com/watch?v=o9pEzgHorH0 ) for some
270
+ hints into practical refactoring examples where simpler functions lead to more
271
+ readable and maintainable code.
272
+
282
273
283
274
#### Descriptive function names
284
275
@@ -456,17 +447,33 @@ git+https://github.com/googleapis/python-firestore.git@ee518b741eb5d7167393c23ba
456
447
457
448
# ## Region Tags
458
449
459
- Sample code may be integrated into Google Cloud Documentation through the use of
460
- region tags, which are comments added to the source code to identify code blocks
461
- that correspond to specific topics covered in the documentation. For example,
462
- see [this
463
- sample](https:// github.com/ GoogleCloudPlatform/ python- docs- samples/ blob/ main/ cloud- sql/ mysql/ sqlalchemy/ main.py)
464
- — the region tags are the comments that begin with `[START ` or ` [END `.
465
-
466
- The use of region tags is beyond the scope of this document, but if you’re using
467
- region tags they should start after the source code header (license / copyright
468
- information), but before imports and global configuration such as initializing
469
- constants.
450
+ Region tags are comments added to the source code that begin with
451
+ `[START region_tag]` and end with `[END region_tag]` . They enclose
452
+ the core sample logic that can be easily copied into a REPL and run.
453
+
454
+ This allows us to integrate this copy- paste callable code into
455
+ documentation directly. Region tags should be placed after the
456
+ license header but before imports that are crucial to the
457
+ sample running.
458
+
459
+ Example:
460
+ ```python
461
+ # This import is not included within the region tag as
462
+ # it is used to make the sample command-line runnable
463
+ import sys
464
+
465
+ # [START example_storage_control_create_folder]
466
+ # This import is included within the region tag
467
+ # as it is critical to understanding the sample
468
+ from google.cloud import storage_control_v2
469
+
470
+
471
+ def create_folder(bucket_name: str , folder_name: str ) -> None :
472
+ print (f " Created folder: { response.name} " )
473
+
474
+
475
+ # [END example_storage_control_create_folder]
476
+ ```
470
477
471
478
# ## Exception Handling
472
479
0 commit comments