Skip to main content

A set of classes and abstractions for working with Tacyt

Project description

Taza is a Python library with a set of abstractions over Tacyt that provides an OO layer over the query language.

Instalation

Install via pip

pip install taza

The libraries for tacyt are vendored inside taza, this is because the Tacyt python client is not distributed using pip.

Usage

The library has currently two main components, the wrapper for the API and the query abstractions.

To use the API wrapper you must instantiate a TazaClient class.

from taza.tacyt.TacytApp import TacytApp
from taza import TazaClient

app = TacytApp(APP_ID, SECREY_KEY)
client = TazaClient(app)

Clients can also be instantiated with a factory method that wraps the TacytApp class. Removing the need of importing Tacyt to the current script.

from taza import TazaClient

client = TazaClient.from_credentials(APP_ID, SECRET_KEY)

Querying tacyt

You can send queries to tacyt for searching apps throught the search_apps_with_query method. This method will handle pagination automatically. It returns a generators, so no query is actually made until the data is collected.

For example, let’s get the SHA256 hash of the apk of whatsapp.

from taza import TazaClient

client = TazaClient.from_credentials(APP_ID, SECRET_KEY)

query = "packageName:com.whatsapp AND origin:GooglePlay"
fields = ["sha256"]

apps = client.search_apps_with_query(query, fields) # No actual connection to Tacyt done here.

for app in apps: # Now the generator starts yielding and therefore connecting to Tacyt.
    print(app)

Query language abstraction

The queries are send as a string to Tacyt, this means that the queries must be managed as strings, which sometimes can get messy. Taza has an OO abstraction that allows to write queries in Python.

First, each predicate can he specified with the cond class. There are shorthands for common predicates (at least common to me).

from taza.query import cond, packageName, fromGooglePlay

q1 = cond('packageName', 'com.company.awesome_app')
q2 = packageName('com.company.awesome_app')

str(q1) # => "packageName:com.company.awesome_app"
str(q2) # => "packageName:com.company.awesome_app"
str(fromGooglePlay) => "origin:GooglePlay"

assert str(q1) == str(q2)

The predicates can be combined with AND, OR and NOT operators.

from taza.query import cond, packageName, fromGooglePlay

q1 = cond('packageName', 'com.company.awesome_app')
q2 = packageName('com.company.awesome_app')

str(q1 & fromGooglePlay) # => "packageName:com.company.awesome_app AND origin:GooglePlay"
str(q2 | -fromGooglePlay) # => "packageName:com.company.awesome_app OR -origin:GooglePlay"

Bear in mind that Tacyt only allows up to 40 predicates per query.

If you need to agreggate several predicates under the same operator, you can use the or_many and and_many functions. They are usefull if you need to define the query programatically under a set of elements.

from taza.query import cond, packageName, fromGooglePlay

q1 = packageName("app1")
q2 = packageName("app2")
q3 = packageName("app3")

assert or_many(q1, q2, q3) == (q1 | q2 | q3)

qs = [fromGooglePlay, cond('versionCode', '42'), packageName('my.another.app')]
assert and_many(*qs) == (fromGooglePlay & cond('versionCode', '42') & packageName('my.another.app'))

These queries are sent to the search_apps_with_query method in the same way that string based queries are sent. The whatsapp example could be rewritten as such.

from taza import TazaClient
from taza.query import packageName, fromGooglePlay

client = TazaClient.from_credentials(APP_ID, SECRET_KEY)

query = packageName('com.whatsapp') & fromGooglePlay
fields = ["sha256"]

apps = client.search_apps_with_query(query, fields) # No actual connection to Tacyt done here.

for app in apps: # Now the generator starts yielding and therefore connecting to Tacyt.
    print(app)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

taza-2.0.0.tar.gz (15.4 kB view details)

Uploaded Source

File details

Details for the file taza-2.0.0.tar.gz.

File metadata

  • Download URL: taza-2.0.0.tar.gz
  • Upload date:
  • Size: 15.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.5

File hashes

Hashes for taza-2.0.0.tar.gz
Algorithm Hash digest
SHA256 22abae5241b4420f9836aea40dece4d7669b4aa24b71a663597970029c4fc87a
MD5 ce3666dc288044b02e41987bf9476b34
BLAKE2b-256 a3e9de8f4c6c349be6cbda53c9e1551eda45f85259484010211052c76d9ce794

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page