Skip to content

Commit

Permalink
feat(sdk/py): update online get api
Browse files Browse the repository at this point in the history
  • Loading branch information
wfxr committed Feb 18, 2022
1 parent b8b0830 commit 1ae419d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
4 changes: 2 additions & 2 deletions sdk/python/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sdk/python/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ name = "oomclient"
crate-type = ["cdylib"]

[dependencies]
oomclient = "0.1.0"
oomclient = "0.1.1-rc.0"
pyo3-asyncio = { version = "0.15", features = ["tokio-runtime"] }
pyo3 = { version = "0.15", features = ["extension-module"] }
tokio = { version = "1.15", features = ["macros", "rt-multi-thread"] }
Expand Down
23 changes: 20 additions & 3 deletions sdk/python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ mod error;

use convert::{err_to_py, py_to_value, value_map_to_py};
use error::Error;
use oomclient::Client as OomClient;
use oomclient::{Client as OomClient, OnlineGetFeatures};
use pyo3::{
exceptions::PyException,
prelude::*,
types::{PyDict, PyType},
};
Expand Down Expand Up @@ -81,11 +82,27 @@ impl Client {
/// features: A list of feature full names.
/// A feature full name has the following format: <group_name>.<feature_name>,
/// for example, txn_stats.count_7d.
/// group: All features of the group will be acquired if set. Conflict with `features` argument.
///
/// Returns:
/// A dict mapping feature full names to feature values.
#[pyo3(text_signature = "(entity_key, features)")]
pub fn online_get<'p>(&self, py: Python<'p>, entity_key: String, features: Vec<String>) -> PyResult<&'p PyAny> {
#[pyo3(text_signature = "(entity_key, features=None, group=None)")]
#[args(features = "None", group = "None")]
pub fn online_get<'p>(
&self,
py: Python<'p>,
entity_key: String,
features: Option<Vec<String>>,
group: Option<String>,
) -> PyResult<&'p PyAny> {
let features = match (features, group) {
(Some(features), None) => OnlineGetFeatures::FeatureNames(features),
(None, Some(group)) => OnlineGetFeatures::GroupName(group),
_ =>
return Err(PyException::new_err(
"features and group cannot exist or absent at the same time",
)),
};
let mut inner = OomClient::clone(&self.inner);
future_into_py(py, async move {
inner
Expand Down

0 comments on commit 1ae419d

Please sign in to comment.