The Ubivar Python library provides convenient access to the Ubivar API from applications written in the Python language. It includes a pre-defined set of classes for API resources.
See the Ubivar API docs.
You don't need this source code unless you want to modify the package. If you just want to use the package, just run:
pip install --upgrade ubivar
or
easy_install --upgrade ubivar
Install from source with:
python setup.py install
- Python Python 3.6+ (PyPy supported)
The library needs to be configured with your API key which is available in My
Ubivar. Set ubivar.api_key
to its value or for apps
that need to use multiple keys during the lifetime of a process, set a key
per-request.
import ubivar
ubivar.api_key = "9spB-ChM6J8NwMEEG ... WsJShd6lVQH7f6xz=".
# Create event
ubivar.Event.create(parameters = {
"id" : "123" # a unique id
, "email" : "abc@gmail.com"
, "names" : "M Abc"
, "account_creation_time" : "2017-05-17 21:50:00"
, "account_id" : "10000"
, "account_n_fulfilled" : "1"
, "account_total_since_created" : "49.40"
, "account_total_cur" : "EUR"
, "invoice_time" : "2017-05-17 21:55:00"
, "invoice_address_country" : "France"
, "invoice_address_place" : "75008 Paris"
, "invoice_address_street1" : "1 Av. des Champs-Élysées"
, "invoice_name" : "M ABC"
, "invoice_phone1" : "0123456789"
, "invoice_phone2" : None
, "transport_date" : "2017-05-18 08:00:00"
, "transport_type" : "Delivery"
, "transport_mode" : "TNT"
, "transport_weight" : "9.000"
, "transport_unit" : "kg"
, "transport_cur" : "EUR"
, "delivery_address_country" : "France"
, "delivery_address_place" : "75008 Paris"
, "delivery_address_street1" : "1 Av. des Champs-Élysées"
, "delivery_name" : "M ABC"
, "delivery_phone1" : "0123450689"
, "customer_ip_address" : "1.2.3.4"
, "pmeth_origin" : "FRA"
, "pmeth_validity" : "0121"
, "pmeth_brand" : "MC"
, "pmeth_bin" : "510000"
, "pmeth_3ds" : "-1"
, "cart_products" : [ "Product ref #12345" ]
, "cart_details" : [{
"name" : "Product ref #12345"
, "pu" : "10.00"
, "n" : "1"
, "amount" : "10.00"
, "cur" : "EUR"
}]
, "cart_n" : "15000"
, "order_payment_accepted" : "2017-05-17 22:00:00"
, "amount_pmeth" : "ABC Payment Service Provider"
, "amount_discounts" : "0.00"
, "amount_products" : "20.00"
, "amount_transport" : "10.00"
, "amount_total" : "30.00"
, "amount_cur" : "EUR"
})
# Retrieve, Update, Delete, or List Events
ubivar.Event.retrieve("123")
ubivar.Event.update("123", parameters={"extra_is_verified": "true", "extra_is_graylisted": "false"}})
ubivar.Event.delete("123")
ubivar.Event.list()
# Create, Retrieve, Update, Delete or List Whitelists
ubivar.FilterWhitelist.create(description="Test", feature="email_domain", is_active="true", value="gmail.com")
ubivar.FilterWhitelist.retrieve("0")
ubivar.FilterWhitelist.update("0", description="Test", feature="email_domain", is_active="true", value="yahoo.com")
ubivar.FilterWhitelist.delete("123")
ubivar.FilterWhitelist.list()
# Specify a different API key for each request
ubivar.Event.list(api_key="9spB-ChM6J8NwMEEG ... WsJShd6lVQH7f6xz=")
The following matrix list the resources (rows), the CRUD actions (columns) and the arguments (cells). The cell links point to the API documentation at https://ubivar.com/docs/python or to the functional tests on github.
- C: Create
- R: Retrieve
- U: Update
- D: Delete
- L: List
123
: resource id{}
: JSON with query parameters
Filter | Default | Example | Description |
---|---|---|---|
order |
id |
order = "-id" |
Sort by decreasing id |
limit |
10 |
limit = 10 |
At most 10 returned results |
gt |
id = {"gt" : 10} |
id greater than 10 |
|
gte |
id = {"gte": 10} |
id greater than or equal |
|
lt |
id = {"lt" : 10} |
id less than |
|
lte |
id = {"lte": 10} |
id less than or equal |
Run all tests (modify -e according to your Python target):
tox -e py36
Run a single test suite:
tox -e py36 -- --test-suite ubivar.test.resources.test_event
Run the linter with:
pip install flake8
flake8 ubivar
The library can be configured to emit logging that will give you better insight
into what it's doing. The info
logging level is usually most appropriate for
production use, but debug
is also available for more verbosity.
There are a few options for enabling it:
- Set the environment variable
UBIVAR_LOG
to the valuedebug
orinfo
$ export UBIVAR_LOG=debug
- Set
ubivar.log
:
import ubivar
ubivar.log = 'debug'
- Enable it through Python's logging module:
import logging
logging.basicConfig()
logging.getLogger('ubivar').setLevel(logging.DEBUG)
They are located here.
Originally inspired from stripe-python. Developed and maintained by Fabrice Colas (fabrice.colas@gmail.com) for Ubivar.