Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Also see:

* [Code Samples](https://github.com/temporalio/samples-python)
* [API Documentation](https://python.temporal.io)
* [Application Development Guide](https://docs.temporal.io/application-development?lang=python)

In addition to features common across all Temporal SDKs, the Python SDK also has the following interesting features:

Expand Down Expand Up @@ -89,7 +90,7 @@ class SayHello:

async def main():
# Create client connected to server at the given address
client = await Client.connect("http://localhost:7233")
client = await Client.connect("localhost:7233")

# Run the worker
worker = Worker(client, task_queue="my-task-queue", workflows=[SayHello], activities=[say_hello])
Expand Down Expand Up @@ -117,7 +118,7 @@ from my_worker_package import SayHello

async def main():
# Create client connected to server at the given address
client = await Client.connect("http://localhost:7233")
client = await Client.connect("localhost:7233")

# Execute a workflow
result = await client.execute_workflow(SayHello.run, "my name", id="my-workflow-id", task_queue="my-task-queue")
Expand Down Expand Up @@ -147,7 +148,7 @@ from temporalio.client import Client

async def main():
# Create client connected to server at the given address and namespace
client = await Client.connect("http://localhost:7233", namespace="my-namespace")
client = await Client.connect("localhost:7233", namespace="my-namespace")

# Start a workflow
handle = await client.start_workflow(MyWorkflow.run, "some arg", id="my-workflow-id", task_queue="my-task-queue")
Expand All @@ -160,6 +161,7 @@ async def main():
Some things to note about the above code:

* A `Client` does not have an explicit "close"
* To enable TLS, the `tls` argument to `connect` can be set to `True` or a `TLSConfig` object
* A single positional argument can be passed to `start_workflow`. If there are multiple arguments, only the
non-type-safe form of `start_workflow` can be used (i.e. the one accepting a string workflow name) and it must be in
the `args` keyword argument.
Expand Down Expand Up @@ -213,7 +215,7 @@ from my_workflow_package import MyWorkflow, my_activity

async def run_worker(stop_event: asyncio.Event):
# Create client connected to server at the given address
client = await Client.connect("http://localhost:7233", namespace="my-namespace")
client = await Client.connect("localhost:7233", namespace="my-namespace")

# Run the worker until the event is set
worker = Worker(client, task_queue="my-task-queue", workflows=[MyWorkflow], activities=[my_activity])
Expand Down Expand Up @@ -677,7 +679,7 @@ class SayHello:
return f"Hello, {name}!"

async def main():
client = await Client.connect("http://localhost:7233")
client = await Client.connect("localhost:7233")
async with Worker(client, task_queue="my-task-queue", workflows=[SayHello]):
result = await client.execute_workflow(SayHello.run, "Temporal",
id="my-workflow-id", task_queue="my-task-queue")
Expand Down
19 changes: 10 additions & 9 deletions temporalio/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
overload,
)

from typing_extensions import Concatenate, ParamSpec, TypedDict
from typing_extensions import Concatenate, TypedDict

import temporalio.api.common.v1
import temporalio.api.enums.v1
Expand Down Expand Up @@ -61,7 +61,7 @@ class Client:

@staticmethod
async def connect(
target_url: str,
target_host: str,
*,
namespace: str = "default",
data_converter: temporalio.converter.DataConverter = temporalio.converter.default(),
Expand All @@ -71,16 +71,16 @@ async def connect(
default_workflow_query_reject_condition: Optional[
temporalio.common.QueryRejectCondition
] = None,
tls_config: Optional[TLSConfig] = None,
tls: Union[bool, TLSConfig] = False,
Copy link
Member

Choose a reason for hiding this comment

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

I'd consider accepting None here too

Copy link
Member Author

Choose a reason for hiding this comment

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

That seems ambiguous. We used to accept None here when this wasn't how you chose whether TLS is used, but now a tls=False is clearer. The parameter changed from "tls configuration" to "tls enabled, with configuration if necessary".

retry_config: Optional[RetryConfig] = None,
static_headers: Mapping[str, str] = {},
identity: Optional[str] = None,
) -> Client:
"""Connect to a Temporal server.

Args:
target_url: URL for the Temporal server. For local development, this
is often "http://localhost:7233".
target_host: `host:port` for the Temporal server. For local
development, this is often "localhost:7233".
namespace: Namespace to use for client calls.
data_converter: Data converter to use for all data conversions
to/from payloads.
Expand All @@ -96,8 +96,9 @@ async def connect(
condition for workflow queries if not set during query. See
:py:meth:`WorkflowHandle.query` for details on the rejection
condition.
tls_config: TLS configuration for connecting to the server. If unset
no TLS connection will be used.
tls: If false, the default, do not use TLS. If true, use system
default TLS configuration. If TLS configuration present, that
TLS configuration will be used.
retry_config: Retry configuration for direct service calls (when
opted in) or all high-level calls made by this client (which all
opt-in to retries by default). If unset, a default retry
Expand All @@ -107,8 +108,8 @@ async def connect(
based on the version of the SDK.
"""
connect_config = temporalio.workflow_service.ConnectConfig(
target_url=target_url,
tls_config=tls_config,
target_host=target_host,
tls=tls,
retry_config=retry_config,
static_headers=static_headers,
identity=identity or "",
Expand Down
36 changes: 31 additions & 5 deletions temporalio/workflow_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
import logging
import os
import socket
import warnings
from abc import ABC, abstractmethod
from dataclasses import dataclass, field
from enum import IntEnum
from typing import Generic, Mapping, Optional, Type, TypeVar
from typing import Generic, Mapping, Optional, Type, TypeVar, Union

import google.protobuf.message
import grpc
Expand Down Expand Up @@ -94,8 +95,8 @@ def _to_bridge_config(self) -> temporalio.bridge.client.ClientRetryConfig:
class ConnectConfig:
"""Config for connecting to the server."""

target_url: str
tls_config: Optional[TLSConfig] = None
target_host: str
tls: Union[bool, TLSConfig] = False
retry_config: Optional[RetryConfig] = None
static_headers: Mapping[str, str] = field(default_factory=dict)
identity: str = ""
Expand All @@ -106,9 +107,34 @@ def __post_init__(self) -> None:
self.identity = f"{os.getpid()}@{socket.gethostname()}"

def _to_bridge_config(self) -> temporalio.bridge.client.ClientConfig:
# Need to create the URL from the host:port. We allowed scheme in the
# past so we'll leave it for only one more version with a warning.
# Otherwise we'll prepend the scheme.
target_url: str
tls_config: Optional[temporalio.bridge.client.ClientTlsConfig]
if "://" in self.target_host:
warnings.warn(
"Target host as URL with scheme no longer supported. This will be an error in future versions."
)
target_url = self.target_host
tls_config = (
self.tls._to_bridge_config()
if isinstance(self.tls, TLSConfig)
else None
)
elif isinstance(self.tls, TLSConfig):
target_url = f"https://{self.target_host}"
tls_config = self.tls._to_bridge_config()
elif self.tls:
target_url = f"https://{self.target_host}"
tls_config = TLSConfig()._to_bridge_config()
else:
target_url = f"http://{self.target_host}"
tls_config = None

return temporalio.bridge.client.ClientConfig(
target_url=self.target_url,
tls_config=self.tls_config._to_bridge_config() if self.tls_config else None,
target_url=target_url,
tls_config=tls_config,
retry_config=self.retry_config._to_bridge_config()
if self.retry_config
else None,
Expand Down
109 changes: 62 additions & 47 deletions tests/helpers/golangserver/go.mod
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
module github.com/temporalio/sdk-python/tests/fixtures/golangserver

go 1.17
go 1.18

replace github.com/cactus/go-statsd-client => github.com/cactus/go-statsd-client v3.2.1+incompatible

require (
github.com/DataDog/temporalite v0.0.0-20220526022626-0f25777b0ee7
go.temporal.io/server v1.16.2
github.com/temporalio/temporalite v0.0.0-20220729234035-c93d79bb8f4d
go.temporal.io/server v1.17.1
)

require (
cloud.google.com/go v0.100.2 // indirect
cloud.google.com/go/compute v1.2.0 // indirect
cloud.google.com/go/iam v0.1.1 // indirect
cloud.google.com/go/storage v1.20.0 // indirect
cloud.google.com/go v0.102.1 // indirect
cloud.google.com/go/compute v1.7.0 // indirect
cloud.google.com/go/iam v0.3.0 // indirect
cloud.google.com/go/storage v1.23.0 // indirect
github.com/apache/thrift v0.0.0-20161221203622-b2a4d4ae21c7 // indirect
github.com/aws/aws-sdk-go v1.42.52 // indirect
github.com/aws/aws-sdk-go v1.44.41 // indirect
github.com/benbjohnson/clock v1.3.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
Expand All @@ -24,83 +24,98 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect
github.com/facebookgo/clock v0.0.0-20150410010913-600d898af40a // indirect
github.com/go-logr/logr v1.2.2 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/gocql/gocql v0.0.0-20211222173705-d73e6b1002a7 // indirect
github.com/gocql/gocql v1.1.0 // indirect
github.com/gogo/googleapis v1.4.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/gogo/status v1.1.0 // indirect
github.com/golang-jwt/jwt/v4 v4.3.0 // indirect
github.com/gogo/status v1.1.1 // indirect
github.com/golang-jwt/jwt/v4 v4.4.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/go-cmp v0.5.7 // indirect
github.com/google/go-cmp v0.5.8 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/googleapis/gax-go/v2 v2.1.1 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.1.0 // indirect
github.com/googleapis/gax-go/v2 v2.4.0 // indirect
github.com/googleapis/go-type-adapters v1.0.0 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed // indirect
github.com/iancoleman/strcase v0.2.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/jmoiron/sqlx v1.3.4 // indirect
github.com/jonboulle/clockwork v0.2.2 // indirect
github.com/jonboulle/clockwork v0.3.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-sqlite3 v1.14.11 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/olivere/elastic v6.2.37+incompatible // indirect
github.com/olivere/elastic/v7 v7.0.31 // indirect
github.com/olivere/elastic/v7 v7.0.32 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pborman/uuid v1.2.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.12.1 // indirect
github.com/prometheus/client_golang v1.12.2 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/common v0.35.0 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect
github.com/robfig/cron v1.2.0 // indirect
github.com/robfig/cron/v3 v3.0.1 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
github.com/stretchr/objx v0.3.0 // indirect
github.com/stretchr/testify v1.7.0 // indirect
github.com/stretchr/objx v0.4.0 // indirect
github.com/stretchr/testify v1.8.0 // indirect
github.com/temporalio/ringpop-go v0.0.0-20211012191444-6f91b5915e95 // indirect
github.com/twmb/murmur3 v1.1.6 // indirect
github.com/uber-common/bark v1.3.0 // indirect
github.com/uber-go/tally/v4 v4.1.1 // indirect
github.com/uber/tchannel-go v1.22.2 // indirect
github.com/uber-go/tally/v4 v4.1.2 // indirect
github.com/uber/tchannel-go v1.22.3 // indirect
github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2 // indirect
go.opencensus.io v0.23.0 // indirect
go.opentelemetry.io/otel v1.4.0 // indirect
go.opentelemetry.io/otel/exporters/prometheus v0.27.0 // indirect
go.opentelemetry.io/otel/internal/metric v0.27.0 // indirect
go.opentelemetry.io/otel/metric v0.27.0 // indirect
go.opentelemetry.io/otel/sdk v1.4.0 // indirect
go.opentelemetry.io/otel/sdk/export/metric v0.27.0 // indirect
go.opentelemetry.io/otel/sdk/metric v0.27.0 // indirect
go.opentelemetry.io/otel/trace v1.4.0 // indirect
go.temporal.io/api v1.7.1-0.20220326004856-88a7c92fb8b4 // indirect
go.temporal.io/sdk v1.14.0 // indirect
go.opentelemetry.io/otel v1.7.0 // indirect
go.opentelemetry.io/otel/exporters/prometheus v0.30.0 // indirect
go.opentelemetry.io/otel/metric v0.30.0 // indirect
go.opentelemetry.io/otel/sdk v1.7.0 // indirect
go.opentelemetry.io/otel/sdk/metric v0.30.0 // indirect
go.opentelemetry.io/otel/trace v1.7.0 // indirect
go.temporal.io/api v1.8.1-0.20220603192404-e65836719706 // indirect
go.temporal.io/sdk v1.15.0 // indirect
go.temporal.io/version v0.3.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/dig v1.13.0 // indirect
go.uber.org/fx v1.16.0 // indirect
go.uber.org/multierr v1.7.0 // indirect
go.uber.org/dig v1.14.1 // indirect
go.uber.org/fx v1.17.1 // indirect
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.21.0 // indirect
golang.org/x/crypto v0.0.0-20220214200702-86341886e292 // indirect
golang.org/x/net v0.0.0-20220325170049-de3da57026de // indirect
golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b // indirect
golang.org/x/sys v0.0.0-20220325203850-36772127a21f // indirect
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d // indirect
golang.org/x/exp v0.0.0-20220613132600-b0d781184e0d // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/net v0.0.0-20220708220712-1185a9018129 // indirect
golang.org/x/oauth2 v0.0.0-20220622183110-fd043fe589d2 // indirect
golang.org/x/sys v0.0.0-20220712014510-0a85c31ab51e // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/time v0.0.0-20220224211638-0e9765cccd65 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
google.golang.org/api v0.68.0 // indirect
golang.org/x/time v0.0.0-20220609170525-579cf78fd858 // indirect
golang.org/x/tools v0.1.11 // indirect
golang.org/x/xerrors v0.0.0-20220609144429-65e65417b02f // indirect
google.golang.org/api v0.85.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20220324131243-acbaeb5b85eb // indirect
google.golang.org/grpc v1.45.0 // indirect
google.golang.org/genproto v0.0.0-20220712132514-bdd2acd4974d // indirect
google.golang.org/grpc v1.48.0 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
gopkg.in/validator.v2 v2.0.0-20210331031555-b37d688a7fb0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
gopkg.in/validator.v2 v2.0.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
lukechampine.com/uint128 v1.2.0 // indirect
modernc.org/cc/v3 v3.36.0 // indirect
modernc.org/ccgo/v3 v3.16.6 // indirect
modernc.org/libc v1.16.10 // indirect
modernc.org/mathutil v1.4.1 // indirect
modernc.org/memory v1.1.1 // indirect
modernc.org/opt v0.1.3 // indirect
modernc.org/sqlite v1.17.3 // indirect
modernc.org/strutil v1.1.2 // indirect
modernc.org/token v1.0.0 // indirect
)
Loading