Anura SDK for Python
Project description
Anura SDK for Python
The Anura SDK for Python makes it easy for developers to access Anura Direct within their Python code, and begin analyzing their traffic. You can get started in minutes by installing the SDK from PyPI or our source code.
Getting Started
- Have an open active account with Anura. You can see more about Anura's offerings here.
- Minimum Requirements - To use the SDK, you will need Python >=3.10.
- Install the SDK - Using pip is the easiest and recommended way to install it. You can install it with the following command:
pip install anura
Or, install from source by using one of the following examples according to your operating system:
Linux/Mac:
git clone https://github.com/anuraio/anura-sdk-python.git
cd anura-sdk-python
python3 -m pip install -r requirements.txt
python3 -m pip install -e .
Windows:
git clone https://github.com/anuraio/anura-sdk-python.git
cd anura-sdk-python
py -m pip install -r requirements.txt
py -m pip install -e .
- View our Quick Examples to immediately begin using the SDK!
Quick Examples
Create the Anura Direct Client
from anura.direct.client import AnuraDirect
direct = AnuraDirect('your-instance-id-goes-here')
Set a custom source, campaign, and additional data for Anura Direct
direct.source = 'your-source-value'
direct.campaign = 'your-campaign-value'
direct.add_additional_data('1', 'your-data-value')
Updating additional data at a specific index
# To update an element of additional data at a specific index,
# simply add the element again but with a new value.
index_to_update = '1'
direct.add_additional_data(index_to_update, 'your-new-data-value')
Removing an element from additional data
index_to_remove = '1'
direct.remove_additional_data(index_to_remove)
Get a result from Anura Direct
try:
result = direct.get_result(
'visitors-ip-address', # required
'visitors-user-agent', # optional
'visitors-app-package-id', # optional
'visitors-device-id' # optional
)
print('result: ' + str(result))
except Exception as e:
print(e)
Get a result from Anura Direct asynchronously
import asyncio
import aiohttp
async def main():
direct = AnuraDirect('your-instance-id')
async with aiohttp.ClientSession() as session:
try:
result = await direct.get_result_async(
session, # required
'visitors-ip-address', # required
'visitors-user-agent', # optional
'visitors-app-package-id', # optional
'visitors-device-id' # optional
)
print('result: ' + str(result))
except Exception as e:
print(e)
asyncio.run(main())
API Reference
AnuraDirect
Can get results from Anura Direct. These results are fetched using Direct's /direct.json API endpoint.
Methods
get_result() -> DirectResult
- Gets a result synchronously from Anura Direct. Raises an exception if an error occurs throughout the result fetching process.
- Exceptions thrown:
AnuraException: if a 4XX, 5XX, or any unknown response is returned from Anura Direct
Parameters:
| Name | Type | Description | Required |
|---|---|---|---|
ip_address |
str |
The IP address of your visitor. Both IPv4 & IPv6 addresses are supported. | Yes |
user_agent |
str |
The user agent string of your visitor | |
app |
str |
The application package identifier of your visitor (when available.) | |
device |
str |
The device identifier of your visitor (when available.) |
get_result_async() -> Awaitable[DirectResult]
- Gets a result asynchronously from Anura Direct. Raises an exception if an error occurs throughout the result fetching process.
- Exceptions thrown:
AnuraException: if a 4XX, 5XX, or any unknown response is returned from Anura Direct
Parameters:
| Name | Type | Description | Required |
|---|---|---|---|
session |
aiohttp.ClientSession |
The aiohttp client session object | Yes |
ip_address |
str |
The IP address of your visitor. Both IPv4 & IPv6 addresses are supported. | Yes |
user_agent |
str |
The user agent string of your visitor | |
app |
str |
The application package identifier of your visitor (when available.) | |
device |
str |
The device identifier of your visitor (when available.) |
add_additional_data(self, key: str, value: str) -> None
- Adds an element of additional data to your
AnuraDirectclient.
remove_additional_data(self, key: str) -> None
- Removes the element of your additional data array located at the provided
key.
@property instance(self) -> str
- Returns the instance you have set within the
AnuraDirectclient.
@property source(self) -> str
- Returns the source you have set within the
AnuraDirectclient.
@property campaign(self) -> str
- Returns the campaign you have set within the
AnuraDirectclient.
@property additional_data(self) -> dict
- Returns the additional data you have set within the
AnuraDirectclient.
@instance.setter instance(self, instance: str) -> None
- Sets the Instance ID of the
AnuraDirectclient to theinstancevalue passed.
@source.setter source(self, source: str) -> None
- Sets the source of the
AnuraDirectclient to thesourcevalue passed.
@campaign.setter campaign(self, campaign: str) -> None
- Sets the campaign of the
AnuraDirectclient to thecampaignvalue passed.
@additional_data.setter additional_data(self, additional_data: dict) -> None
- Sets the additional data of the
AnuraDirectclient to theadditional_datavalue passed.
DirectResult
The result upon a successful call to get_result() or get_result_async() from the AnuraDirect client. It contains not only the result from Anura Direct, but some other methods to help you use the result as well.
Methods
is_suspect() -> bool
- Returns whether or not the visitor has been determined to be suspect.
is_non_suspect() -> bool
- Returns whether or not the visitor has been determined to be non-suspect.
is_mobile() -> bool
- Returns whether or not the visitor has been determined to be on a mobile device.
Properties
result: str
- Besides using the
is_suspect()oris_non_suspect()methods, you are also able to directly access the result value.
rule_sets: str[] | None
- If you have return rule sets enabled, you will be able to see which specific rules were violated upon a suspect result. This value will be
Noneif the visitor is non-suspect, or if you do not have return rule sets enabled. - You can talk to support about enabling or disabling the return rule sets feature.
invalid_traffic_type: str | None
- If you have invalid traffic type enabled, you will be able to access which type of invalid traffic occurred upon a suspect result.
- You can talk to support about enabling or disabling the return invalid traffic type feature.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file anura-0.0.1.tar.gz.
File metadata
- Download URL: anura-0.0.1.tar.gz
- Upload date:
- Size: 17.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f5aa7df2cab93cafa80c4a520411a1abb503d99cff6fcbe69b249974b9a55dba
|
|
| MD5 |
c75de708ce1930d0665dde85ebf55aa8
|
|
| BLAKE2b-256 |
e9208d78090c47a290d538fbb4952b6df27c47d73efdb6c8a34876b187f72721
|
Provenance
The following attestation bundles were made for anura-0.0.1.tar.gz:
Publisher:
python-publish.yml on anuraio/anura-sdk-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
anura-0.0.1.tar.gz -
Subject digest:
f5aa7df2cab93cafa80c4a520411a1abb503d99cff6fcbe69b249974b9a55dba - Sigstore transparency entry: 154562123
- Sigstore integration time:
-
Permalink:
anuraio/anura-sdk-python@62a67fa5bb34da926402cecd1213e27f7804a19a -
Branch / Tag:
refs/tags/initial - Owner: https://github.com/anuraio
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@62a67fa5bb34da926402cecd1213e27f7804a19a -
Trigger Event:
release
-
Statement type:
File details
Details for the file anura-0.0.1-py3-none-any.whl.
File metadata
- Download URL: anura-0.0.1-py3-none-any.whl
- Upload date:
- Size: 17.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
084cebbd8d4b3f2a208d87785b37a80bc33de7a9c7555472060ad057b056883d
|
|
| MD5 |
5ccf55d6ccc32351139ae9a11cdb56a2
|
|
| BLAKE2b-256 |
51ed8136060ffa6e3ddf119ee4086bf2b88cc36ff76ba38722af60762ffa16de
|
Provenance
The following attestation bundles were made for anura-0.0.1-py3-none-any.whl:
Publisher:
python-publish.yml on anuraio/anura-sdk-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
anura-0.0.1-py3-none-any.whl -
Subject digest:
084cebbd8d4b3f2a208d87785b37a80bc33de7a9c7555472060ad057b056883d - Sigstore transparency entry: 154562125
- Sigstore integration time:
-
Permalink:
anuraio/anura-sdk-python@62a67fa5bb34da926402cecd1213e27f7804a19a -
Branch / Tag:
refs/tags/initial - Owner: https://github.com/anuraio
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@62a67fa5bb34da926402cecd1213e27f7804a19a -
Trigger Event:
release
-
Statement type: