Skip to content

Commit 243855b

Browse files
authored
Merge pull request #117 from pecheneff/dpecheniev/v6.0.0
[MSUE-232] - Add typing. Apply code linters. Update documentation
2 parents 5b3a75d + 3c2984f commit 243855b

28 files changed

+4388
-3352
lines changed

.flake8

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[flake8]
2+
ignore = E501,W503
3+
per-file-ignores = __init__.py:F401
4+
max-line-length = 79
5+
disable-noqa = true

.github/workflows/ci.yml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ permissions:
1212
contents: read
1313

1414
env:
15-
mock_version_python3: "5.0.1"
16-
requests_version_python3: "2.28.2"
1715
ACCOUNT_ID: ${{ secrets.ACCOUNT_ID }}
1816
API_KEY: ${{ secrets.API_KEY }}
1917

@@ -26,10 +24,13 @@ jobs:
2624
uses: actions/setup-python@v3
2725
with:
2826
python-version: "3.10.14"
29-
- name: Install test dependencies
27+
- name: Install the library
3028
run: |
31-
pip install mock=="${{ env.mock_version_python3 }}"
32-
pip install requests=="${{ env.requests_version_python3 }}"
29+
pip install -e .
30+
- name: Run linters
31+
run: |
32+
pip install -U pre-commit
33+
pre-commit run -v --all-files
3334
- name: Run tests
3435
run: |
3536
python -m unittest discover
@@ -43,7 +44,7 @@ jobs:
4344
uses: actions/setup-python@v3
4445
with:
4546
python-version: "3.10.14"
46-
- name: run-integration-tests-python3
47+
- name: Run integration tests
4748
run: |
48-
pip3 install .
49-
python3 test_integration_app/main.py
49+
pip install .
50+
python test_integration_app/main.py

.github/workflows/publishing2PyPI.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
VERSION=$(cat ./sift/version.py | grep -E -i '^VERSION.*' | cut -d'=' -f2 | cut -d\' -f2)
1919
[[ $VERSION == "NOT_SET" ]] && echo "Version in version.py NOT_SET" && exit 1
2020
echo "curr_version=$(echo $VERSION)" >> $GITHUB_ENV
21-
- name: Compare package version and Releas tag
21+
- name: Compare package version and Release tag
2222
run: |
2323
TAG=${GITHUB_REF##*/}
2424
if [[ $TAG != *"$curr_version"* ]]; then
@@ -27,11 +27,12 @@ jobs:
2727
fi
2828
- name: Create distribution files
2929
run: |
30-
python3 setup.py sdist
30+
python -m pip install build
31+
python -m build
3132
- name: Upload distribution files
3233
env:
3334
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
3435
TWINE_USER: ${{ secrets.USER }}
3536
run: |
36-
python3 -m pip install --user --upgrade twine
37-
ls dist/ | xargs -I % python3 -m twine upload --repository pypi dist/%
37+
python -m pip install --user --upgrade twine
38+
ls dist/ | xargs -I % python -m twine upload --repository pypi dist/%

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
__pycache__
12
*.py[cod]
23

34
# C extensions

.pre-commit-config.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
repos:
2+
- repo: https://github.com/crate-ci/typos
3+
rev: v1.31.1
4+
hooks:
5+
- id: typos
6+
args: [ --force-exclude ]
7+
- repo: https://github.com/pycqa/isort
8+
rev: 5.13.2
9+
hooks:
10+
- id: isort
11+
- repo: https://github.com/psf/black
12+
rev: 24.8.0
13+
hooks:
14+
- id: black
15+
- repo: https://github.com/pycqa/flake8
16+
rev: 7.1.2
17+
hooks:
18+
- id: flake8
19+
- repo: https://github.com/pre-commit/mirrors-mypy
20+
rev: v1.14.1
21+
hooks:
22+
- id: mypy
23+
args: [ --install-types, --non-interactive ]
24+
additional_dependencies: [ types-requests ]

.travis.yml

Lines changed: 0 additions & 10 deletions
This file was deleted.

CHANGES.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
6.0.0 2025-05-05
2+
================
3+
4+
- Added support for Python 3.13
5+
- Dropped support for Python < 3.8
6+
- Added typing annotations overall the library
7+
- Updated doc strings with actual information
8+
- Fixed an issue when the client could send requests with invalid version in the "User-Agent" header
9+
- Changed the type of the `abuse_types` parameter in the `client.get_decisions()` method
10+
11+
INCOMPATIBLE CHANGES INTRODUCED IN 6.0.0:
12+
13+
- Dropped support for Python < 3.8
14+
- Passing `abuse_types` as a comma-separated string to the `client.get_decisions()` is deprecated.
15+
16+
Previously, `client.get_decisions()` method allowed to pass `abuse_types` parameter as a
17+
comma-separated string e.g. `abuse_types="legacy,payment_abuse"`. This is deprecated now.
18+
Starting from 6.0.0 callers must pass `abuse_types` parameter to the `client.get_decisions()`
19+
method as a sequence of string literals e.g. `abuse_types=("legacy", "payment_abuse")`. The same
20+
way as it passed to the other client's methods which receive `abuse_types` parameter.
21+
122
5.6.1 2024-10-08
223
- Updated implementation to use Basic Authentication instead of passing `API_KEY` as a request parameter for the following calls:
324
- `client.score()`
@@ -127,7 +148,7 @@ INCOMPATIBLE CHANGES INTRODUCED IN API V205:
127148
1.1.2.0 (2015-02-04)
128149
====================
129150

130-
- Added Unlabel functionaly
151+
- Added Unlabel functionality
131152
- Minor bug fixes.
132153

133154
1.1.1.0 (2014-09-3)

CONTRIBUTING.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
2+
## Setting up the environment
3+
4+
1. Install [pyenv](https://github.com/pyenv/pyenv?tab=readme-ov-file#installation)
5+
2. Setup virtual environment
6+
7+
```sh
8+
# install necessary Python version
9+
pyenv install 3.13.2
10+
11+
# create a virtual environment
12+
pyenv virtualenv 3.13.2 v3.13
13+
pyenv activate v3.13
14+
```
15+
16+
3. Upgrade pip
17+
18+
```sh
19+
pip install -U pip
20+
```
21+
22+
4. Install pre-commit
23+
24+
```sh
25+
pip install -U pre-commit
26+
pre-commit install
27+
```
28+
29+
5. Install the library:
30+
31+
```sh
32+
pip install -e .
33+
```
34+
35+
## Testing
36+
37+
Before submitting a change, make sure the following commands run without
38+
errors from the root folder of the repository:
39+
40+
```sh
41+
python -m unittest discover
42+
```
43+
44+
## Integration testing app
45+
46+
For testing the app with real calls it is possible to run the integration testing app,
47+
it makes calls to almost all Sift public API endpoints to make sure the library integrates
48+
well. At the moment, the app is run on every merge to master
49+
50+
#### How to run it locally
51+
52+
1. Add env variable `API_KEY` with the valid Api Key associated from the account
53+
54+
```sh
55+
export API_KEY="api_key"
56+
```
57+
58+
1. Add env variable `ACCOUNT_ID` with the valid account id
59+
60+
```sh
61+
export ACCOUNT_ID="account_id"
62+
```
63+
64+
3. Run the following under the project root folder
65+
66+
```sh
67+
# run the app
68+
python test_integration_app/main.py
69+
```

README.md

Lines changed: 35 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,22 @@
11
# Sift Python Bindings
22

33
Bindings for Sift's APIs -- including the
4-
[Events](https://sift.com/resources/references/events-api.html),
5-
[Labels](https://sift.com/resources/references/labels-api.html),
4+
[Events](https://developers.sift.com/docs/python/events-api/,
5+
[Labels](https://developers.sift.com/docs/python/labels-api/),
66
and
7-
[Score](https://sift.com/resources/references/score-api.html)
7+
[Score](https://developers.sift.com/docs/python/score-api/)
88
APIs.
99

10-
1110
## Installation
1211

13-
Set up a virtual environment with virtualenv (otherwise you will need
14-
to make the pip calls as sudo):
15-
16-
virtualenv venv
17-
source venv/bin/activate
18-
19-
Get the latest released package from pip:
20-
21-
Python 2:
22-
23-
pip install Sift
24-
25-
Python 3:
26-
27-
pip3 install Sift
28-
29-
or install newest source directly from GitHub:
30-
31-
Python 2:
32-
33-
pip install git+https://github.com/SiftScience/sift-python
34-
35-
Python 3:
36-
37-
pip3 install git+https://github.com/SiftScience/sift-python
38-
12+
```sh
13+
# install from PyPi
14+
pip install Sift
15+
```
3916

4017
## Documentation
4118

42-
Please see [here](https://sift.com/developers/docs/python/events-api/overview) for the
19+
Please see [here](https://developers.sift.com/docs/python/apis-overview) for the
4320
most up-to-date documentation.
4421

4522
## Changelog
@@ -48,19 +25,13 @@ Please see
4825
[the CHANGELOG](https://github.com/SiftScience/sift-python/blob/master/CHANGES.md)
4926
for a history of all changes.
5027

51-
Note, that in v2.0.0, the API semantics were changed to raise an
52-
exception in the case of error to be more pythonic. Client code will
53-
need to be updated to catch `sift.client.ApiException` exceptions.
54-
55-
5628
## Usage
5729

5830
Here's an example:
5931

6032
```python
6133

62-
import json
63-
import sift.client
34+
import sift
6435

6536
client = sift.Client(api_key='<your API key here>', account_id='<your account ID here>')
6637

@@ -85,12 +56,17 @@ properties = {
8556
}
8657

8758
try:
88-
response = client.track("$transaction", properties)
89-
if response.is_ok():
90-
print "Successfully tracked event"
59+
response = client.track(
60+
"$transaction",
61+
properties,
62+
)
9163
except sift.client.ApiException:
9264
# request failed
9365
pass
66+
else:
67+
if response.is_ok():
68+
print("Successfully tracked event")
69+
9470

9571
# Track a transaсtion event and receive a score with percentiles in response (sync flow).
9672
# Note: `return_score` or `return_workflow_status` must be set `True`.
@@ -111,15 +87,24 @@ properties = {
11187
}
11288

11389
try:
114-
response = client.track("$transaction", properties, return_score=True, include_score_percentiles=True, abuse_types=["promotion_abuse", "content_abuse", "payment_abuse"])
115-
if response.is_ok():
116-
score_response = response.body["score_response"]
117-
print(score_response)
90+
response = client.track(
91+
"$transaction",
92+
properties,
93+
return_score=True,
94+
include_score_percentiles=True,
95+
abuse_types=("promotion_abuse", "content_abuse", "payment_abuse"),
96+
)
11897
except sift.client.ApiException:
11998
# request failed
12099
pass
100+
else:
101+
if response.is_ok():
102+
score_response = response.body["score_response"]
103+
print(score_response)
104+
121105

122-
# To include `warnings` field to Events API response via calling `track()` method, set it by the `include_warnings` param:
106+
# In order to include `warnings` field to Events API response via calling
107+
# `track()` method, set it by the `include_warnings` param:
123108
try:
124109
response = client.track("$transaction", properties, include_warnings=True)
125110
# ...
@@ -130,12 +115,12 @@ except sift.client.ApiException:
130115
# Request a score for the user with user_id 23056
131116
try:
132117
response = client.score(user_id)
133-
s = json.dumps(response.body)
134-
print s
135-
136118
except sift.client.ApiException:
137119
# request failed
138120
pass
121+
else:
122+
print(response.body)
123+
139124

140125
try:
141126
# Label the user with user_id 23056 as Bad with all optional fields
@@ -211,6 +196,7 @@ send_properties = {
211196
}
212197
}
213198
}
199+
214200
try:
215201
response = client.verification_send(send_properties)
216202
except sift.client.ApiException:
@@ -241,35 +227,4 @@ try:
241227
except sift.client.ApiException:
242228
# request failed
243229
pass
244-
245-
```
246-
247-
## Testing
248-
249-
Before submitting a change, make sure the following commands run without
250-
errors from the root dir of the repository:
251-
252-
python -m unittest discover
253-
python3 -m unittest discover
254-
255-
## Integration testing app
256-
257-
For testing the app with real calls it is possible to run the integration testing app,
258-
it makes calls to almost all our public endpoints to make sure the library integrates
259-
well. At the moment, the app is run on every merge to master
260-
261-
#### How to run it locally
262-
263-
1. Add env variable `ACCOUNT_ID` with the valid account id
264-
2. Add env variable `API_KEY` with the valid Api Key associated from the account
265-
3. Run the following under the project root folder
266-
```
267-
# uninstall the lib from the local env (if it was installed)
268-
pip uninstall sift
269-
270-
# install the lib from the local source code
271-
pip install ../sift-python
272-
273-
# run the app
274-
python test_integration_app/main.py
275230
```

0 commit comments

Comments
 (0)