Skip to content

Commit d0d9fa1

Browse files
authored
docs(samples): add REST sample and test for Anti Money Laundering AI (GoogleCloudPlatform#12529)
* docs(samples): add REST sample and test for Anti Money Laundering AI * update code owners * fix header check * rename AML AI directory; add review team to CODEOWNERS
1 parent 2d26696 commit d0d9fa1

7 files changed

Lines changed: 162 additions & 0 deletions

File tree

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
/practice-folder/**/* engelke@google.com
102102

103103
# ---* Fully Eng Owned
104+
/aml-ai/**/* @GoogleCloudPlatform/aml-ai @GoogleCloudPlatform/python-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers
104105
/appengine/**/* @GoogleCloudPlatform/serverless-runtimes @GoogleCloudPlatform/python-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers
105106
/appengine/standard_python3/spanner/* @GoogleCloudPlatform/api-spanner-python @GoogleCloudPlatform/python-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers
106107
/asset/**/* @GoogleCloudPlatform/cloud-asset-analysis-team @GoogleCloudPlatform/cloud-asset-platform-team @GoogleCloudPlatform/python-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers

.github/blunderbuss.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ assign_issues_by:
109109
- GoogleCloudPlatform/api-bigquery
110110

111111
# AppEco individuals
112+
- labels:
113+
- "api: aml-ai"
114+
to:
115+
- nickcook
112116
- labels:
113117
- "api: bigquery"
114118
to:

aml-ai/README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Anti Money Laundering AI Python Samples
2+
3+
This directory contains samples for Anti Money Laundering AI (AML AI). Use this API to produce risk scores and accompanying explainability output to support your alerting and investigation process. For more information, see the
4+
[Anti Money Laundering AI documentation](https://cloud.google.com/financial-services/anti-money-laundering/).
5+
6+
## Setup
7+
8+
To run the samples, you need to first follow the steps in
9+
[Set up a project and permissions](https://cloud.google.com/financial-services/anti-money-laundering/docs/set-up-project-permissions).
10+
11+
For more information on authentication, refer to the
12+
[Authentication Getting Started Guide](https://cloud.google.com/docs/authentication/getting-started).
13+
14+
## Install Dependencies
15+
16+
1. Clone python-docs-samples repository and change directories to the sample directory
17+
you want to use.
18+
19+
$ git clone https://github.com/GoogleCloudPlatform/python-docs-samples.git
20+
21+
1. Install [pip](https://pip.pypa.io/) and
22+
[virtualenv](https://virtualenv.pypa.io/) if you do not already have them. You
23+
may want to refer to the
24+
[Python Development Environment Setup Guide](https://cloud.google.com/python/setup)
25+
for Google Cloud Platform for instructions.
26+
27+
1. Create a virtualenv. Samples are compatible with Python 3.6+.
28+
29+
$ virtualenv env
30+
$ source env/bin/activate
31+
32+
1. Install the dependencies needed to run the samples.
33+
34+
$ pip install -r requirements.txt
35+
36+
## Testing
37+
38+
Make sure to enable the AML AI API on the test project. Set the following
39+
environment variable:
40+
41+
* `GOOGLE_CLOUD_PROJECT`

aml-ai/list_locations.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Copyright 2024 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Google Cloud Anti Money Laundering AI sample for listing the Cloud locations
16+
of the API.
17+
Example usage:
18+
python list_locations.py --project_id <project-id>
19+
"""
20+
21+
# [START antimoneylaunderingai_list_locations]
22+
23+
import argparse
24+
import os
25+
26+
import google.auth
27+
from google.auth.transport import requests
28+
29+
30+
def list_locations(
31+
project_id: str,
32+
) -> google.auth.transport.Response:
33+
"""Lists the AML AI locations using the REST API."""
34+
35+
# TODO(developer): Uncomment these lines and replace with your values.
36+
# project_id = 'my-project' # The Google Cloud project ID.
37+
38+
# Gets credentials from the environment. google.auth.default() returns credentials and the
39+
# associated project ID, but in this sample, the project ID is passed in manually.
40+
credentials, _ = google.auth.default(
41+
scopes=[
42+
"https://www.googleapis.com/auth/cloud-platform",
43+
]
44+
)
45+
authed_session = requests.AuthorizedSession(credentials)
46+
47+
# URL to the AML AI API endpoint and version
48+
base_url = "https://financialservices.googleapis.com/v1"
49+
url = f"{base_url}/projects/{project_id}/locations/"
50+
# Sets required "application/json" header on the request
51+
headers = {"Content-Type": "application/json; charset=utf-8"}
52+
53+
response = authed_session.get(url, headers=headers)
54+
response.raise_for_status()
55+
print(response.text)
56+
return response
57+
58+
59+
# [END antimoneylaunderingai_list_locations]
60+
61+
if __name__ == "__main__":
62+
parser = argparse.ArgumentParser()
63+
parser.add_argument(
64+
"--project_id",
65+
default=(os.environ.get("GOOGLE_CLOUD_PROJECT")),
66+
help="Google Cloud project name",
67+
)
68+
args = parser.parse_args()
69+
70+
list_locations(
71+
args.project_id,
72+
)

aml-ai/locations_test.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Copyright 2024 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import json
16+
import os
17+
18+
import pytest
19+
20+
import list_locations
21+
22+
project_id = os.environ["GOOGLE_CLOUD_PROJECT"]
23+
24+
25+
def test_locations(capsys: pytest.fixture) -> None:
26+
# List the locations of the API
27+
r = list_locations.list_locations(project_id)
28+
locations = json.loads(r.text)
29+
30+
found = False
31+
name = f"projects/{project_id}/locations/us-central1"
32+
33+
for location in locations["locations"]:
34+
location_name = location["name"]
35+
if location_name == name:
36+
found = True
37+
break
38+
39+
assert found

aml-ai/requirements-test.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pytest==8.2.0

aml-ai/requirements.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
google-api-python-client==2.131.0
2+
google-auth-httplib2==0.2.0
3+
google-auth==2.19.1
4+
requests==2.31.0

0 commit comments

Comments
 (0)