Metadata-Version: 2.4
Name: oai_statsig_python_core
Version: 0.35.0rc1
Classifier: Programming Language :: Rust
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Requires-Dist: requests
Requires-Dist: typing-extensions
Requires-Dist: protobuf>=6.33.6 ; extra == 'typed'
Provides-Extra: typed
Summary: Statsig Python bindings for the Statsig Core SDK.
Home-Page: https://statsig.com/
Author: Statsig, Daniel Loomb <daniel@statsig.com>
Author-email: Statsig, Daniel Loomb <daniel@statsig.com>
License: ISC
Requires-Python: >=3.10
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: changelog, https://github.com/statsig-io/statsig-server-core/releases
Project-URL: documentation, https://docs.statsig.com/server-core/python-core
Project-URL: homepage, https://statsig.com
Project-URL: repository, https://github.com/statsig-io/statsig-server-core/tree/main/statsig-pyo3

<h1 align="center">
	<a href="https://statsig.com/?ref=gh_server_core">
		<img src="https://github.com/statsig-io/js-client-monorepo/assets/95646168/ae5499ed-20ff-4584-bf21-8857f800d485" />
	</a>
    <div />
	<a href="https://statsig.com/?ref=gh_server_core">Statsig</a>
</h1>

<p align="center">
	<a href="https://github.com/statsig-io/statsig-server-core/blob/main/LICENSE">
        	<img src="https://img.shields.io/badge/license-ISC-blue.svg?colorA=1b2528&colorB=ccfbc7&style=for-the-badge">
    	</a>
	<a href="https://www.npmjs.com/package/@oai-statsig/statsig-node-core">
		<img src="https://img.shields.io/npm/v/@oai-statsig/statsig-node-core.svg?colorA=1b2528&colorB=b2d3ff&style=for-the-badge">
	</a>
	<a href="https://statsig.com/community?ref=gh_server_core">
        	<img src="https://img.shields.io/badge/slack-statsig-brightgreen.svg?logo=slack&colorA=1b2528&colorB=FFF8BA&style=for-the-badge">
    	</a>
</p>

Statsig helps you move faster with feature gates (feature flags), and/or dynamic configs. It also allows you to run A/B/n tests to validate your new features and understand their impact on your KPIs. If you're new to Statsig, check out our product and create an account at [statsig.com](https://www.statsig.com/?ref=gh_server_core).


## Getting Started

Read through the [Documentation](https://docs.statsig.com/server-core?ref=gh_server_core) or check out the [Samples](https://github.com/statsig-io/statsig-server-core/tree/main/examples).

## ID-list file routing and fallback

`download_id_list_file_api` selects the preferred base URL for file downloads.
Enable `fallback_to_statsig_api` to try the original file URL from the manifest
after an overridden request fails with a retryable network error, provided that
URL belongs to the trusted HTTPS OpenAI CDN origin:

```rust
let options = statsig_rust::StatsigOptions {
    download_id_list_file_api: Some("http://statsig-proxy:8080".to_string()),
    fallback_to_statsig_api: Some(true),
    ..Default::default()
};
```

Fallback accepts only `https://statsigcdn.openai.com` with the default port or
explicit `:443`. Fallback sends no request or SDK credentials to other manifest
origins; the original request error is returned. Fallback does not follow redirects.
Custom network providers must implement `send_without_redirects`; otherwise the
fallback returns an error without sending a request.

All ID-list file downloads, including direct CDN, proxy, and fallback requests,
preserve the URL's path and query except for legacy `range` parameters, which are
removed. Every request sends `Range`, `statsig-id-list-file-size`, and
`Accept-Encoding: identity` headers, preserving the file identity and byte offset
for incremental updates. Partial responses require a valid `Content-Range`
matching the requested offset and received body length. They may use `206` or,
for compatibility, `200`. A `200` without `Content-Range` means the complete
available file from byte zero; the SDK applies only bytes after the requested
offset. Available bytes may be behind or ahead of the manifest: the SDK advances
by bytes actually applied and keeps polling while below the advertised size.
Responses that make no progress or have inconsistent ranges use the remaining
retry budget without publishing the refresh. Partial bodies without
`Content-Range` are unsupported; a malformed header is rejected even when the
status is `200`.

Set `fallback_to_statsig_api` to `Some(false)` or leave it unset to keep file
downloads strictly on the selected destination. There is no fallback attempt when
the override resolves to the original URL, no override is set, or the request
fails with an authentication rejection (401/403) or another non-retryable error.
Response parsing failures do not trigger fallback. This uses the existing option
across language bindings; wrappers that disable it continue to opt out.

A successful proxy request makes no additional request. Primary and fallback
requests share the same per-file attempt budget (three attempts by default).
The next synchronization starts with the configured override again.

## Read-only data stores

Rust data stores can override `DataStoreTrait::is_read_only()`; Python `DataStore`
subclasses can override the synchronous `is_read_only()` method:

```python
def is_read_only(self) -> bool:
    return not self.is_leader
```

The default is `False`, preserving existing writable stores. Return `True` for a
follower that only consumes shared cache entries. Bootstrap/polling reads and
config hydration/evaluation remain enabled, but full network responses no longer
build or compress hydrated cache snapshots or call the datastore's write methods.
Delta responses continue to skip snapshot writes. Keep the role stable during an
update. A failing Python capability check is treated as read-only.

## Packages

Python protobuf-typed reads and explicit publication callbacks are described in
[Python typed configs](docs/python-typed-configs.md).

Bindings

- Node [[npm](https://www.npmjs.com/package/@oai-statsig/statsig-node-core)] [[source](https://github.com/statsig-io/statsig-server-core/blob/main/statsig-node)] [[docs](https://docs.statsig.com/server-core/node-core?ref=gh_server_core)]

- Python [[pypi](https://pypi.org/project/oai-statsig-python-core)] [[source](https://github.com/statsig-io/statsig-server-core/blob/main/statsig-pyo3)] [[docs](https://docs.statsig.com/server-core/python-core?ref=gh_server_core)] 


- Java [[maven](https://central.sonatype.com/artifact/com.oaistatsig/javacore)] [[source](https://github.com/openai/statsig-priv-server-core/tree/main/statsig-java)] [[docs](https://docs.statsig.com/server-core/java-core?ref=gh_server_core)]

- Rust [[crates.io](https://crates.io/crates/oai-statsig-rust)] [[source](https://github.com/statsig-io/statsig-server-core/tree/main/statsig-rust)] [[docs](https://docs.statsig.com/server-core/rust-core?ref=gh_server_core)] 




## Community

If you need any assitance or just have a question, feel free to reach out to us on [Slack](https://statsig.com/community?ref=gh_server_core).

