Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DRV-302: Introduce streaming api #165

Merged
merged 1 commit into from
Nov 17, 2020
Merged

DRV-302: Introduce streaming api #165

merged 1 commit into from
Nov 17, 2020

Conversation

trevorsibanda
Copy link
Contributor

Introduces the streaming api for the Python driver.

Notable changes and limitations.

  • For backwards compatibility, using asyncio was not implemented. However most of our users report using Python 3.4+ so this will likely be implemented in the near future. Related: Is async implementation in the roadmap of this library? #161
  • Started stream subscriptions are blocking by default. If started asynchronously by passing blocking=False to the FaunaClient stream method, the event loop will be started in a separate thread.
  • Currently each stream has its own HTTP/2 connection(separate from the FaunaClient connection). A connection pool for stream connections and/or using the HTTP/2 adapter for the FaunaClient are necessary to effectively utilize HTTP/2 multiplexing for streams.
  • Python 3.6+ deprecations with hyper. To support HTTP/2 we use hyper, however there are several deprecation warnings from hyper and currently hyper
  • Error event triggered on server disconnects were only tested on Linux using software TCP resets. i.e by running ss -K dst 127.0.0.1 dport = 8443 with an active stream.
  • Document helper API was not implemented. (as in the Js Driver )

@trevorsibanda
Copy link
Contributor Author

Working on fixing the CI. Will open a new PR shortly for that

@trevorsibanda trevorsibanda force-pushed the streaming-api branch 8 times, most recently from 980f093 to 21967ae Compare November 2, 2020 16:12
@agourlay
Copy link

agourlay commented Nov 2, 2020

I did a first pass and it looks good so far 👍
I will have another look tomorrow.

faunadb/client.py Outdated Show resolved Hide resolved
faunadb/streams/client.py Outdated Show resolved Hide resolved
Current limitations:
Python requests module uses HTTP1; hyper is used for HTTP/2
"""
def __init__(self, client, expression, options):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use kwargs for options?

@@ -187,6 +189,31 @@ def query(self, expression, timeout_millis=None):
"""
return self._execute("POST", "", _wrap(expression), with_txn_time=True, query_timeout_ms=timeout_millis)

def stream(self, expression, options=None, on_start=None, on_error=None, on_version=None, on_history=None, blocking=True):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use kwargs for options and event handlers?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would lean more on not using kwargs since we have a finite and well defined set of possible events and names of event handlers. IMO it also improves readability and documentation.

faunadb/streams/client.py Outdated Show resolved Hide resolved
@trevorsibanda trevorsibanda force-pushed the streaming-api branch 2 times, most recently from 110886e to d7734a8 Compare November 4, 2020 09:09
faunadb/client.py Outdated Show resolved Hide resolved
@trevorsibanda trevorsibanda force-pushed the streaming-api branch 2 times, most recently from 8fbd64e to 8f92ca9 Compare November 4, 2020 15:38
faunadb/streams/client.py Outdated Show resolved Hide resolved
@agourlay
Copy link

LGTM feature wise but my level in Python does not allow me to give a real approval.

benjumanji
benjumanji previously approved these changes Nov 13, 2020
faunadb/streams/client.py Outdated Show resolved Hide resolved
faunadb/streams/client.py Outdated Show resolved Hide resolved
faunadb/streams/client.py Outdated Show resolved Hide resolved
faunadb/streams/events.py Outdated Show resolved Hide resolved
Copy link
Contributor

@erickpintor erickpintor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@trevorsibanda trevorsibanda merged commit 98b1c7e into master Nov 17, 2020
@cleve-fauna cleve-fauna deleted the streaming-api branch February 11, 2022 01:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants