56 Commits

Author SHA1 Message Date
Xuan Wang
ac31fb0f61 [Python example] Fix version in generated code in example folder (#37665)
Fix: https://github.com/grpc/grpc/issues/37610
<!--

If you know who should review your pull request, please assign it to
that
person, otherwise the pull request would get assigned randomly.

If your pull request is for a specific language, please add the
appropriate
lang label.

-->
2024-09-25 10:43:15 -07:00
Xuan Wang
3546a3e930 [Python Distrib] Change warning to RuntimeError for version incompatibility (#37466)
<!--

If you know who should review your pull request, please assign it to that
person, otherwise the pull request would get assigned randomly.

If your pull request is for a specific language, please add the appropriate
lang label.

-->

Closes #37466

PiperOrigin-RevId: 662606899
2024-08-13 12:14:09 -07:00
Xuan Wang
4ad050e457 [Python] Update generated code warning version (#37229)
Push back the date of changing warning to error in case so that it won't be a blocker for CSM launch.
<!--

If you know who should review your pull request, please assign it to that
person, otherwise the pull request would get assigned randomly.

If your pull request is for a specific language, please add the appropriate
lang label.

-->

Closes #37229

PiperOrigin-RevId: 652924647
2024-07-16 11:49:53 -07:00
Xuan Wang
811bb258d8 [Python Otel] Use registered method at server side (#36371)
Add registered method change to sync stack server.

## Note
* We're keeping both generic and registered handler in generated stubs (`*_pb2_grpc.py`) because registered method flow is not implemented in aysncio yet, since the stub is used for both sync and asyncio, we can't remove generic method flow until we fully implement the registered method flow in asyncio.

<!--

If you know who should review your pull request, please assign it to that
person, otherwise the pull request would get assigned randomly.

If your pull request is for a specific language, please add the appropriate
lang label.

-->

Closes #36371

PiperOrigin-RevId: 629842051
2024-05-01 14:43:15 -07:00
Xuan Wang
c910004328 [Python Stub] Add version check to stubs generated by grpcio_tools (#35906)
The stubs generated by grpcio_tools should always be used with [the same or higher version of grpcio](https://github.com/grpc/grpc/blob/master/tools/distrib/python/grpcio_tools/setup.py#L313), this change will add a run time check for this requirement inside the generated stubs and therefor enforce this requirement.

Please note for now we're just printing a warning for incorrect usage, we'll **change it to an error** soon.

Example warning message:
```
/usr/local/google/home/xuanwn/workspace/misc/grpc/examples/python/helloworld/helloworld_pb2_grpc.py:21: RuntimeWarning: The grpc package installed is at version 1.60.1, but the generated code in helloworld_pb2_grpc.py depends on grpcio>=1.63.0.dev0. Please upgrade your grpc module to grpcio>=1.63.0.dev0 or downgrade your generated code using grpcio-tools<=1.60.1. This warning will become an error in 1.64.0, scheduled for release on May 14,2024.
```
<!--

If you know who should review your pull request, please assign it to that
person, otherwise the pull request would get assigned randomly.

If your pull request is for a specific language, please add the appropriate
lang label.

-->

Closes #35906

PiperOrigin-RevId: 615659471
2024-03-13 22:47:01 -07:00
Xuan Wang
2c9b599e5e [Python O11Y] Reapply registered method change (#35850)
This reverts commit a18279db2e.

<!--

If you know who should review your pull request, please assign it to that
person, otherwise the pull request would get assigned randomly.

If your pull request is for a specific language, please add the appropriate
lang label.

-->

Closes #35850

PiperOrigin-RevId: 607476066
2024-02-15 15:36:27 -08:00
Xuan Wang
a18279db2e [Python O11Y] Revert registered method change (#35522)
We're having some issues internally, rolling this change back for now and wait for the affected users to figure out a solution.

This reverts: https://github.com/grpc/grpc/pull/35002, https://github.com/grpc/grpc/pull/35482 and 6872a7a473

<!--

If you know who should review your pull request, please assign it to that
person, otherwise the pull request would get assigned randomly.

If your pull request is for a specific language, please add the appropriate
lang label.

-->

Closes #35522

PiperOrigin-RevId: 597671989
2024-01-11 15:40:10 -08:00
Xuan Wang
9a7c0b5f57 [Python Observability] Allow create call with registered method (#35002)
Based on [OpenTelemetry Metrics gRFC](https://github.com/grpc/proposal/blob/master/A66-otel-stats.md#opentelemetry-metrics), we should recored unregistered RPC method name as `other`, this PR adds the ability to pass register method information when creating a call.

We'll consider calls created using generated stubs as registered, note that this won't prevent user from setting `registered_method=True` when creating calls manually.

This is also enabled for simple stub flow but **NOT enabled for AsyncIO**, we'll add that later when start working on AsyncIO Observability.
<!--

If you know who should review your pull request, please assign it to that
person, otherwise the pull request would get assigned randomly.

If your pull request is for a specific language, please add the appropriate
lang label.

-->

Closes #35002

PiperOrigin-RevId: 596719121
2024-01-08 15:30:17 -08:00
Sergii Tkachenko
de6ed9ba9f [Python] Migrate from yapf to black (#33138)
- Switched  from yapf to black
- Reconfigure isort for black
- Resolve black/pylint idiosyncrasies 

Note: I used `--experimental-string-processing` because black was
producing "implicit string concatenation", similar to what described
here: https://github.com/psf/black/issues/1837. While currently this
feature is experimental, it will be enabled by default:
https://github.com/psf/black/issues/2188. After running black with the
new string processing so that the generated code merges these `"hello" "
world"` strings concatenations, then I removed
`--experimental-string-processing` for stability, and regenerated the
code again.

To the reviewer: don't even try to open "Files Changed" tab 😄 It's
better to review commit-by-commit, and ignore `run black and isort`.
2023-06-09 15:08:55 -07:00
Xuan Wang
a190831789 Add examples for timeout, kepp_alive, reflection and health_checking (#32243)
* Add timeout example

* Add pb2 file to example

* Remove .proto file

* Add keep_alive example

* Add refelction client

* fixes

* Add example for health_check

* Changes based on comments

* Fix pylint
2023-02-03 14:11:27 -08:00
AmosWang
166824205e Print info when server starts (#30964) 2022-09-14 15:54:01 -07:00
Yash Tibrewal
41ec08c69a Update third_party/protobuf to 3.21.4 (#30377)
* Update third_party/protobuf

* run tools/distrib/python/make_grpcio_tools.py

* regenerate protos for ruby, php

* update build_handwritten.yaml

* regenerate projects

* Build - Use :well_known_type_protos instead of :well_known_protos

* Fix target

* Update upb

* Update Python for Protobuf 4.21 (#140)

* Update protobuf dependency on grpcio-tools

* Off by one

* Drop python 3.6 support

* Try upgrading pip

* And in the other script

* Try to figure out if we're compatible with abi3

* See what we've already got installed

* Update the requirements.txt file I didn't know existed

* And here too

* See what's installed

* Let's try that again

* Remove

* Try to confirm version

* Let me see the generated code

* Fix non-Bazel test runner

* Work for all test directories

* Regenerate example protos

* Clean up

* Generate .pyi files

* Fix type checking and linting

* Exclude pyi files from isort

* Upgrade to 3.21.4

* Update iwyu to get around messy protobuf IWYU rules

Co-authored-by: Richard Belleville <gnossen@gmail.com>
2022-08-04 09:39:49 -07:00
Xiao
ad3f591af3 [Aio] Fix typo in async graceful shutdown example (#29521)
Background: https://github.com/grpc/grpc/pull/26622
2022-05-03 10:51:44 -07:00
Lidi Zheng
2231c2ba77 Introduce Python import sorting to our sanity test suite (#26768)
* Add isort_code.sh to sanity tests

* Run tools/distrib/isort_code.sh

* Fine tune the import order for relative imports

* Make pylint and project generation happy

* Fix a few corner cases

* Use --check instead of --diff

* The import order impacts test result somehow

* Make isort print diff and check output at the same time

* Let tools/run_tests/python_utils be firstparty library

* Run isort against latest HEAD
2021-07-26 12:31:21 -07:00
Lidi Zheng
933b10d2a8 Add a correct graceful shutdwon example for the asyncio API (#26622) 2021-07-08 10:58:58 -07:00
Sergii Tkachenko
8db79e2e71 Python style: reformat code using updated yapf 0.30.0 2021-01-13 14:00:12 -05:00
Lidi Zheng
40a5a655af Polish and add AsyncIO examples
* Add type annotations
* Add test for asyncio auth example
* Use dynamic stubs to allow same code runs manually and under Bazel
* Add grpcio-tools as a Bazel dependency
* asyncio.run is not yet existed in 3.6
* Improve readability
2020-12-08 13:44:43 -08:00
Tim Hughes
80799468bd lint 2020-10-05 21:56:48 +01:00
Tim Hughes
0b3fc20b83 clean up docstrings and remove unused imports 2020-10-05 21:30:57 +01:00
Tim Hughes
7aff6c4555 dont need ThreadPoolExecutor in asyncio 2020-10-04 21:51:05 +01:00
Tim Hughes
cef8dbf27c Adds python aio helloworld examples 2020-10-01 00:05:11 +01:00
Patrice Chalin
4c4933e056 Docs: fix links to quick start pages 2020-06-16 08:40:59 -04:00
Esun Kim
7be821ac47 Yapf all target python sources 2020-01-03 09:25:10 -08:00
Richard Belleville
e32980fba2 Quit waiting for a day 2019-08-05 16:19:49 -07:00
Lidi Zheng
05b61a5199 Use Pylint to lint gRPC Python examples 2018-12-20 12:10:53 -08:00
Lidi Zheng
5fc0547a94 Add basicConfig to prepare to log future exception 2018-11-30 09:56:40 -08:00
Youngchan Kim
2e2ef9dcdf Run YAPF check for python example 2018-10-23 13:45:25 +09:00
Youngchan Kim
832460bb94 Add link - gRPC Python package documents 2018-10-23 13:45:25 +09:00
Youngchan Kim
0f9733eb85 Update timeout: 1 -> 10 2018-10-23 13:45:25 +09:00
Youngchan Kim
c4c112bc50 Update keepalive timeout: 10 -> 10000 2018-10-23 13:45:25 +09:00
Youngchan Kim
f65615d4cd Update example description 2018-10-23 13:45:25 +09:00
Youngchan Kim
0a925095be Simplify example 2018-10-23 13:45:25 +09:00
Youngchan Kim
cf09d16ca8 Add python example - channel options 2018-10-23 13:45:25 +09:00
Mehrdad Afshari
5ffb9bf8c4 Add server reflection guide for Python 2018-08-06 13:40:53 -07:00
Nathaniel Manista
8234d14113 Close channels in examples 2018-06-14 17:16:04 +00:00
ncteisen
848a749f7a yapf examples/python 2017-12-12 10:59:01 -08:00
Nathaniel Manista
61efbcd27a Regenerate example Python generated code 2017-09-11 23:48:47 +00:00
Mehrdad Afshari
bb3d95b643 Use https://grpc.io consistently as the canonical URL 2017-07-10 22:24:28 +00:00
Jan Tattermusch
7897ae9308 auto-fix most of licenses 2017-06-08 11:22:41 +02:00
Nathaniel Manista
c15ee83882 Update Python examples with fresh generated code 2016-12-21 21:05:19 +00:00
Mark Mandel
9929e6c85c Remove run_codegen.py from python helloworld example
Since we no longer reference `run_codegen.py` in the Quick Start for
Python, remove it from the repository to avoid confusion.
2016-10-17 17:53:15 -07:00
Nathaniel Manista
6c09b3b29e Truncate Python example READMEs to grpc.io links 2016-08-20 15:26:20 +00:00
Nathaniel Manista
46585e23f1 Update examples to GA API 2016-07-15 22:33:50 +00:00
Ken Payson
5c88bc660c Updated example codegen to use grpcio-tools 2016-06-30 11:54:50 -07:00
yang-g
b0de7163ad Add proto comments to generated _pb2.py files 2016-05-03 15:48:19 -07:00
Craig Tiller
6169d5f7b0 Update copyrights 2016-03-31 07:46:18 -07:00
Leifur Halldor Asgeirsson
4df39871d0 python3-compatible syntax for python examples 2016-03-18 16:24:29 -04:00
Masood Malekghassemi
13e9faa644 Remove outdated scripts 2016-02-17 12:40:07 -08:00
Craig Tiller
897e4fe2ad Update copyrights 2015-12-22 15:03:40 -08:00
Masood Malekghassemi
77ebadc662 Add grace=0 to server stop in Python example
Fixes #4122
2015-11-16 16:48:44 -08:00