Skip to content

Introduction

The "SDK" is the zapy python library. It allows to use your request from Python. It is a Python package that allows developers to extend and customize some behavior of the program.

Main file

Using a main file or a python test file is required to use the SDK.

Modules

The library has the following modules

base             # contains base classes
requests         # loads, manage and perform requests
api              # exposes an API
store            # global persistance
templating       # evaluate expressions and render
test             # custom test classes
cli              # exposes a cli
utils            # internal utility
    module # for importing ipynb from python and vice versa

Examples

Global hooks

Intercept and modify every request with custom code.

from zapy import requests, HttpxArguments

@requests.hooks.pre_request
async def global_auth(httpx_args: HttpxArguments):
    httpx_args['auth'] = ('foo', 'bar')
from zapy.requests import hooks, HttpxArguments
from zapy.base import Metadata

@hooks.pre_request
async def on_global(httpx_args: HttpxArguments, metadata: Metadata):
    if 'basic_auth' in metadata.tags:
        httpx_args['auth'] = ('foo', 'bar')
    elif 'digest_auth' in metadata.tags:
        httpx_args['auth'] = httpx.DigestAuth("my_user", "password123")

Stores

Add Stores variables on bootstrap or at runtime.

from zapy.store import use_store

# on bootstrap
store = use_store()
store.my_var = 'foo'

Send request

Import or create requests and send them.

from zapy import requests

req = requests.from_file('my_zapy.zapy')
response = await req.send()
print(response.json())

Execute chain

Load a chain to execute it and use the variables created.

from zapy.utils import module
rel_path = Path('tests/assets')
# invoke jupyter notebook
chain = await module.load_ipynb(rel_path / 'chain_import.ipynb', variables={
    'rel_path': rel_path
})
# access a variable
print(chain.out_response)