Skip to content

Commit a2df5d2

Browse files
authored
Update protos, re-export them for easier use (#120)
* Update protos, re-export them for easier use * Mark "schema" type as unsupported in context shape * Resolve some formatting issues
1 parent 43c0ad7 commit a2df5d2

File tree

7 files changed

+255
-135
lines changed

7 files changed

+255
-135
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
- Re-exported Protocol Buffer types including `ConfigValue`, `StringList`, `ProtoContext`, `ContextSet`, `ContextShape`, `LogLevel`, `Json`, and `Schema` for easier access.
6+
37
## [0.11.2] - 2025-02-24
48

59
- Updates ConfigValueType's union to include dict to better support json values [#117]
10+
- Renamed encrypted content paths
611

712
## [0.11.1] - 2025-02-20
813

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,23 @@ result = prefab_cloud_python.get_client().enabled("my-first-feature-flag", conte
3333
print("my-first-feature-flag is:", result)
3434
```
3535

36+
## Protocol Buffer Types
37+
38+
If you need to work with the underlying Protocol Buffer types, the following are re-exported for convenience:
39+
40+
```python
41+
from prefab_cloud_python import ConfigValue, StringList, ProtoContext, ContextSet, ContextShape, LogLevel, Json, Schema
42+
43+
# Create a config value
44+
config_value = ConfigValue(string="example value")
45+
46+
# Create a JSON value
47+
json_value = ConfigValue(json=Json(json='{"key": "value"}'))
48+
49+
# Create a Schema value
50+
schema_value = Schema(definition='{"type": "object", "properties": {"name": {"type": "string"}}}')
51+
```
52+
3653
See full documentation https://docs.prefab.cloud/docs/sdks/python
3754

3855
## Development

prefab.proto

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ message ConfigValue {
2727
Provided provided = 12;
2828
IsoDuration duration = 15;
2929
Json json = 16;
30+
Schema schema = 17;
3031
}
3132
optional bool confidential = 13; // don't log or telemetry this value
3233
optional string decrypt_with = 14; // key name to decrypt with
@@ -91,6 +92,7 @@ enum ConfigType {
9192
SEGMENT = 4;
9293
LIMIT_DEFINITION = 5;
9394
DELETED = 6;
95+
SCHEMA = 7;
9496
}
9597

9698
message Config {
@@ -104,6 +106,7 @@ message Config {
104106
optional int64 draft_id = 8;
105107
ValueType value_type = 9;
106108
bool send_to_client_sdk = 10; // default value of a boolean in proto3 is false
109+
optional string schema_key = 11;
107110

108111
enum ValueType {
109112
NOT_SET_VALUE_TYPE = 0; // proto null
@@ -464,3 +467,14 @@ message ClientStats {
464467
int64 end = 2;
465468
uint64 dropped_event_count = 3;
466469
}
470+
471+
472+
message Schema {
473+
enum SchemaType {
474+
UNKNOWN = 0;
475+
ZOD = 1;
476+
JSON_SCHEMA = 2;
477+
}
478+
string schema = 1;
479+
SchemaType schema_type = 2;
480+
}

prefab_cloud_python/__init__.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
"""
2+
Prefab Cloud Python client library.
3+
4+
This module provides access to the Prefab Cloud configuration and feature flag service.
5+
6+
Main components:
7+
- Client: The main client for interacting with Prefab Cloud
8+
- Options: Configuration options for the client
9+
- Context: Context information for evaluating configs and feature flags
10+
11+
Re-exported Protocol Buffer types:
12+
- ConfigValue: Represents a configuration value
13+
- StringList: Represents a list of strings
14+
- ProtoContext: Protocol buffer Context class
15+
- ContextSet: Collection of contexts
16+
- ContextShape: Shape information for contexts
17+
- LogLevel: Enumeration of log levels
18+
- Json: Represents JSON data in configuration values
19+
- Schema: Represents schema validation for configuration values
20+
"""
21+
122
from typing import Optional
223

324
from . import _internal_logging
@@ -10,6 +31,19 @@
1031
from .feature_flag_client import FeatureFlagClient
1132
from .config_client import ConfigClient
1233

34+
# Re-export Protocol Buffer types for easier access
35+
import prefab_pb2
36+
from prefab_pb2 import (
37+
ConfigValue,
38+
StringList,
39+
Context as ProtoContext,
40+
ContextSet,
41+
ContextShape,
42+
LogLevel,
43+
Json,
44+
Schema,
45+
)
46+
1347
log = _internal_logging.InternalLogger(__name__)
1448

1549

prefab_pb2.py

Lines changed: 134 additions & 130 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

prefab_pb2.pyi

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class _ConfigTypeEnumTypeWrapper(google.protobuf.internal.enum_type_wrapper._Enu
4747
SEGMENT: _ConfigType.ValueType # 4
4848
LIMIT_DEFINITION: _ConfigType.ValueType # 5
4949
DELETED: _ConfigType.ValueType # 6
50+
SCHEMA: _ConfigType.ValueType # 7
5051

5152
class ConfigType(_ConfigType, metaclass=_ConfigTypeEnumTypeWrapper): ...
5253

@@ -58,6 +59,7 @@ LOG_LEVEL: ConfigType.ValueType # 3
5859
SEGMENT: ConfigType.ValueType # 4
5960
LIMIT_DEFINITION: ConfigType.ValueType # 5
6061
DELETED: ConfigType.ValueType # 6
62+
SCHEMA: ConfigType.ValueType # 7
6163
global___ConfigType = ConfigType
6264

6365
class _LogLevel:
@@ -150,6 +152,7 @@ class ConfigValue(google.protobuf.message.Message):
150152
PROVIDED_FIELD_NUMBER: builtins.int
151153
DURATION_FIELD_NUMBER: builtins.int
152154
JSON_FIELD_NUMBER: builtins.int
155+
SCHEMA_FIELD_NUMBER: builtins.int
153156
CONFIDENTIAL_FIELD_NUMBER: builtins.int
154157
DECRYPT_WITH_FIELD_NUMBER: builtins.int
155158
int: builtins.int
@@ -172,6 +175,8 @@ class ConfigValue(google.protobuf.message.Message):
172175
def duration(self) -> global___IsoDuration: ...
173176
@property
174177
def json(self) -> global___Json: ...
178+
@property
179+
def schema(self) -> global___Schema: ...
175180
confidential: builtins.bool
176181
"""don't log or telemetry this value"""
177182
decrypt_with: builtins.str
@@ -192,17 +197,18 @@ class ConfigValue(google.protobuf.message.Message):
192197
provided: global___Provided | None = ...,
193198
duration: global___IsoDuration | None = ...,
194199
json: global___Json | None = ...,
200+
schema: global___Schema | None = ...,
195201
confidential: builtins.bool | None = ...,
196202
decrypt_with: builtins.str | None = ...,
197203
) -> None: ...
198-
def HasField(self, field_name: typing_extensions.Literal["_confidential", b"_confidential", "_decrypt_with", b"_decrypt_with", "bool", b"bool", "bytes", b"bytes", "confidential", b"confidential", "decrypt_with", b"decrypt_with", "double", b"double", "duration", b"duration", "int", b"int", "int_range", b"int_range", "json", b"json", "limit_definition", b"limit_definition", "log_level", b"log_level", "provided", b"provided", "string", b"string", "string_list", b"string_list", "type", b"type", "weighted_values", b"weighted_values"]) -> builtins.bool: ...
199-
def ClearField(self, field_name: typing_extensions.Literal["_confidential", b"_confidential", "_decrypt_with", b"_decrypt_with", "bool", b"bool", "bytes", b"bytes", "confidential", b"confidential", "decrypt_with", b"decrypt_with", "double", b"double", "duration", b"duration", "int", b"int", "int_range", b"int_range", "json", b"json", "limit_definition", b"limit_definition", "log_level", b"log_level", "provided", b"provided", "string", b"string", "string_list", b"string_list", "type", b"type", "weighted_values", b"weighted_values"]) -> None: ...
204+
def HasField(self, field_name: typing_extensions.Literal["_confidential", b"_confidential", "_decrypt_with", b"_decrypt_with", "bool", b"bool", "bytes", b"bytes", "confidential", b"confidential", "decrypt_with", b"decrypt_with", "double", b"double", "duration", b"duration", "int", b"int", "int_range", b"int_range", "json", b"json", "limit_definition", b"limit_definition", "log_level", b"log_level", "provided", b"provided", "schema", b"schema", "string", b"string", "string_list", b"string_list", "type", b"type", "weighted_values", b"weighted_values"]) -> builtins.bool: ...
205+
def ClearField(self, field_name: typing_extensions.Literal["_confidential", b"_confidential", "_decrypt_with", b"_decrypt_with", "bool", b"bool", "bytes", b"bytes", "confidential", b"confidential", "decrypt_with", b"decrypt_with", "double", b"double", "duration", b"duration", "int", b"int", "int_range", b"int_range", "json", b"json", "limit_definition", b"limit_definition", "log_level", b"log_level", "provided", b"provided", "schema", b"schema", "string", b"string", "string_list", b"string_list", "type", b"type", "weighted_values", b"weighted_values"]) -> None: ...
200206
@typing.overload
201207
def WhichOneof(self, oneof_group: typing_extensions.Literal["_confidential", b"_confidential"]) -> typing_extensions.Literal["confidential"] | None: ...
202208
@typing.overload
203209
def WhichOneof(self, oneof_group: typing_extensions.Literal["_decrypt_with", b"_decrypt_with"]) -> typing_extensions.Literal["decrypt_with"] | None: ...
204210
@typing.overload
205-
def WhichOneof(self, oneof_group: typing_extensions.Literal["type", b"type"]) -> typing_extensions.Literal["int", "string", "bytes", "double", "bool", "weighted_values", "limit_definition", "log_level", "string_list", "int_range", "provided", "duration", "json"] | None: ...
211+
def WhichOneof(self, oneof_group: typing_extensions.Literal["type", b"type"]) -> typing_extensions.Literal["int", "string", "bytes", "double", "bool", "weighted_values", "limit_definition", "log_level", "string_list", "int_range", "provided", "duration", "json", "schema"] | None: ...
206212

207213
global___ConfigValue = ConfigValue
208214

@@ -456,6 +462,7 @@ class Config(google.protobuf.message.Message):
456462
DRAFT_ID_FIELD_NUMBER: builtins.int
457463
VALUE_TYPE_FIELD_NUMBER: builtins.int
458464
SEND_TO_CLIENT_SDK_FIELD_NUMBER: builtins.int
465+
SCHEMA_KEY_FIELD_NUMBER: builtins.int
459466
id: builtins.int
460467
project_id: builtins.int
461468
key: builtins.str
@@ -470,6 +477,7 @@ class Config(google.protobuf.message.Message):
470477
value_type: global___Config.ValueType.ValueType
471478
send_to_client_sdk: builtins.bool
472479
"""default value of a boolean in proto3 is false"""
480+
schema_key: builtins.str
473481
def __init__(
474482
self,
475483
*,
@@ -483,10 +491,14 @@ class Config(google.protobuf.message.Message):
483491
draft_id: builtins.int | None = ...,
484492
value_type: global___Config.ValueType.ValueType = ...,
485493
send_to_client_sdk: builtins.bool = ...,
494+
schema_key: builtins.str | None = ...,
486495
) -> None: ...
487-
def HasField(self, field_name: typing_extensions.Literal["_draft_id", b"_draft_id", "changed_by", b"changed_by", "draft_id", b"draft_id"]) -> builtins.bool: ...
488-
def ClearField(self, field_name: typing_extensions.Literal["_draft_id", b"_draft_id", "allowable_values", b"allowable_values", "changed_by", b"changed_by", "config_type", b"config_type", "draft_id", b"draft_id", "id", b"id", "key", b"key", "project_id", b"project_id", "rows", b"rows", "send_to_client_sdk", b"send_to_client_sdk", "value_type", b"value_type"]) -> None: ...
496+
def HasField(self, field_name: typing_extensions.Literal["_draft_id", b"_draft_id", "_schema_key", b"_schema_key", "changed_by", b"changed_by", "draft_id", b"draft_id", "schema_key", b"schema_key"]) -> builtins.bool: ...
497+
def ClearField(self, field_name: typing_extensions.Literal["_draft_id", b"_draft_id", "_schema_key", b"_schema_key", "allowable_values", b"allowable_values", "changed_by", b"changed_by", "config_type", b"config_type", "draft_id", b"draft_id", "id", b"id", "key", b"key", "project_id", b"project_id", "rows", b"rows", "schema_key", b"schema_key", "send_to_client_sdk", b"send_to_client_sdk", "value_type", b"value_type"]) -> None: ...
498+
@typing.overload
489499
def WhichOneof(self, oneof_group: typing_extensions.Literal["_draft_id", b"_draft_id"]) -> typing_extensions.Literal["draft_id"] | None: ...
500+
@typing.overload
501+
def WhichOneof(self, oneof_group: typing_extensions.Literal["_schema_key", b"_schema_key"]) -> typing_extensions.Literal["schema_key"] | None: ...
490502

491503
global___Config = Config
492504

@@ -1725,3 +1737,36 @@ class ClientStats(google.protobuf.message.Message):
17251737
def ClearField(self, field_name: typing_extensions.Literal["dropped_event_count", b"dropped_event_count", "end", b"end", "start", b"start"]) -> None: ...
17261738

17271739
global___ClientStats = ClientStats
1740+
1741+
@typing_extensions.final
1742+
class Schema(google.protobuf.message.Message):
1743+
DESCRIPTOR: google.protobuf.descriptor.Descriptor
1744+
1745+
class _SchemaType:
1746+
ValueType = typing.NewType("ValueType", builtins.int)
1747+
V: typing_extensions.TypeAlias = ValueType
1748+
1749+
class _SchemaTypeEnumTypeWrapper(google.protobuf.internal.enum_type_wrapper._EnumTypeWrapper[Schema._SchemaType.ValueType], builtins.type): # noqa: F821
1750+
DESCRIPTOR: google.protobuf.descriptor.EnumDescriptor
1751+
UNKNOWN: Schema._SchemaType.ValueType # 0
1752+
ZOD: Schema._SchemaType.ValueType # 1
1753+
JSON_SCHEMA: Schema._SchemaType.ValueType # 2
1754+
1755+
class SchemaType(_SchemaType, metaclass=_SchemaTypeEnumTypeWrapper): ...
1756+
UNKNOWN: Schema.SchemaType.ValueType # 0
1757+
ZOD: Schema.SchemaType.ValueType # 1
1758+
JSON_SCHEMA: Schema.SchemaType.ValueType # 2
1759+
1760+
SCHEMA_FIELD_NUMBER: builtins.int
1761+
SCHEMA_TYPE_FIELD_NUMBER: builtins.int
1762+
schema: builtins.str
1763+
schema_type: global___Schema.SchemaType.ValueType
1764+
def __init__(
1765+
self,
1766+
*,
1767+
schema: builtins.str = ...,
1768+
schema_type: global___Schema.SchemaType.ValueType = ...,
1769+
) -> None: ...
1770+
def ClearField(self, field_name: typing_extensions.Literal["schema", b"schema", "schema_type", b"schema_type"]) -> None: ...
1771+
1772+
global___Schema = Schema

tests/test_context_shape.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def test_mapping_is_exhaustive(self):
4040
"confidential",
4141
"decrypt_with",
4242
"duration",
43+
"schema",
4344
]
4445

4546
supported = list(

0 commit comments

Comments
 (0)