sgmarket api authentication
pip install sgmarkets-api-auth==0.3.0
This repo is a helper package for clients (and employees) to autheticate with SG Markets APIs.
From terminal:
# download and install package from pypi.org
pip install sgmarkets_api_auth
Create a file my_secret.txt
(or pick the name) in your home directory.
C:\Users\youraccountsname
.~/youraccountsname
.This file must contain your secrets in the following format:
# not compulsory in interactive mode
SG_LOGIN=myownsglogin
SG_PASSWORD=myownsgpwd
# compulsory even as blank
PROXY_LOGIN=myownproxylogin
PROXY_PASSWORD=myownproxypwd
# compulsory even as blank
PROXY_HOST=myownproxyhost
PROXY_PORT=myownproxyport
Pass this file name as argument to the Api object.
from sgmarkets_api_auth import Api
# default name is 'my_secret.txt'
a = Api()
# default name is 'my_secret.txt'
a = Api(path_secret='my_custom_secret.txt')
# to see the logs - default is False
a = Api(verbose=True)
# to force update token - default is False
a = Api(update_token=True)
# interactive mode
# to request password and optionally login through form
# (login prefilled if SG_LOGIN defined in my_secret.txt)
# default is False
a = Api(interactive=True)
# to remove secrets and token from disk
a.clear_secret_token()
See the demo notebook.
Read the demo notebooks for various APIs in the same gitlab sgmarkets organization.
There you can see how to use the Api
object to make a request to an SG Markets API and analyse the response.
It is sometimes convenient to store an API response object on disk, particularly if the API request is long.
In order to do so this package contains a pickle/unpickle utility functions.
from sgmarkets_api_auth.util import topickle, unpickle
path = os.path.join('path', 'to', 'filename.pk')
# to store obj - a response object for example
# compresslevel is 4 by default on a scale from 0 to 9
topickle(path, obj, compresslevel=1)
# to retrieve obj
obj2 = unpickle(path)