Chuyển đến nội dung chính

Bộ điều hợp framework

SDK Python

Một client phía máy chủ cho backend Python, không dùng gì ngoài thư viện chuẩn. Mỗi lần gọi đều nêu tên người dùng, vì một tiến trình phục vụ rất nhiều người.

Nơi phát hành

prodantix-sdk on PyPI. Requires Python 3.9 or newer.

Cài đặt

Bash
pip install prodantix-sdk

Mỗi lần gọi đều nêu tên người dùng

Client trên trình duyệt có thể nhớ ai đang dùng nó; máy chủ thì không. Vì vậy id người dùng là đối số đầu tiên của capture, identify, group và các lượt đọc hộp thư. Đó là khác biệt hình dạng duy nhất so với client trình duyệt và di động.

Python
import os
from prodantix import Client

client = Client(
    api_key=os.environ["PRODANTIX_PUBLIC_KEY"],
    host="https://eu.api.prodantix.com",
)

client.capture("user-123", "order.completed", properties={"total": 42, "currency": "XAF"})
client.identify("user-123", set_props={"plan": "pro"})
client.group("user-123", "company", "acme", properties={"seats": 10})

for message in client.get_inbox("user-123"):
    ...

client.mark_message_read("user-123", "message-id")

Cờ từ xa và cờ cục bộ

Phép kiểm từ xa hỏi máy chủ và mang tính quyết định. Phép kiểm cục bộ đánh giá bản chụp bộ quy tắc đã lưu đệm ngay trong tiến trình, không phải đi về ở mỗi lần gọi, và đó là thứ một đường dẫn nóng cần.

Python
# Remote: asks the server, and is the authoritative answer.
if client.is_feature_enabled("user-123", "new-checkout"):
    ...

# Local: evaluated in process from a cached snapshot, no round trip per call.
if client.is_feature_enabled_local("user-123", "new-checkout", properties={"plan": "pro"}):
    ...

every_flag = client.get_all_flags("user-123")

# Every per-flag read records one $feature_flag_called exposure.
variant = client.get_variant("user-123", "new-checkout")
if variant and variant["key"] == "treatment":
    ...

# A flag targeting a cohort reads the user's memberships from the store;
# pass cohorts=[...] to skip the lookup.
if client.is_feature_enabled_local("user-123", "members", cohorts=["<cohort id>"]):
    ...

# With stream_flags=True the client holds a Socket.IO subscription and refetches
# the snapshot when a flag changes, instead of waiting for the 30s poll.
client = Client(api_key=os.environ["PRODANTIX_PUBLIC_KEY"], host="https://eu.api.prodantix.com", stream_flags=True)

Gửi đi và tắt

Sự kiện đi vào một hàng đợi an toàn với luồng, và bộ đẩy nền gửi chúng theo lô, theo số lượng hoặc theo bộ đếm giờ, cái nào đến trước. Hãy dùng client như một trình quản lý ngữ cảnh, lô cuối cùng sẽ được gửi khi khối kết thúc.

Python
with Client(api_key=..., host=...) as client:
    client.capture("user-123", "page.viewed")
# the final batch is flushed here

# Without the context manager, flush and stop the background flusher yourself.
client.shutdown()
ArgumentDefaultPurpose
api_keyrequiredPublic project key (pdx_pub_…)
hostrequiredIngest base URL
flags_hosthostBase URL for the flags and inbox endpoints
flush_at20Queue size that triggers an immediate flush
flush_interval_s10.0Background flush cadence; 0 or less disables the timer
max_queue_size1000Cap; the oldest events are dropped on overflow
max_retries3Delivery retry attempts
request_timeout_s10.0Per-request timeout
default_propertiesNoneA dict or a callable merged into every event
on_errorno-opCalled with any capture or background error
stream_flagsFalseHold a Socket.IO subscription to flag changes and refetch the snapshot on push
socket_factorystdlib clientBuilds the websocket the flag stream uses; the test seam