Python wrapper around the different PriceCypher APIs
Project description
PriceCypher Python SDK
Python wrapper around the different PriceCypher APIs.
Usage
Installation
Simply execute pip install pricecypher-sdk
Dataset SDK
import asyncio
from pricecypher import Datasets
async def handle_page(page, page_nr, last_page):
""" This function will be called for each individual page of transactions that is received."""
print(f'Handling page {page_nr}/{last_page}')
print(f'Nr of transactions in page: {len(page)}')
print(f'Handling page {page_nr}/{last_page} done')
async def main():
async with Datasets(BEARER_TOKEN) as ds:
# Specify desired columns to be requested for transactions
columns = [
{'name_dataset': 'cust_group', 'filter': ['Big', 'Small'], 'key': 'group'},
{'representation': 'cost_price', 'aggregate': 'sum', 'key': 'cost_price'}
]
index = asyncio.create_task(ds.index())
meta = asyncio.create_task(ds.get_meta(DATASET_ID))
scopes = asyncio.create_task(ds.get_scopes(DATASET_ID))
values = asyncio.create_task(ds.get_scope_values(DATASET_ID, SCOPE_ID))
summary = asyncio.create_task(ds.get_transaction_summary(DATASET_ID))
transactions = asyncio.create_task(ds.get_transactions(DATASET_ID, AGGREGATE, columns))
print('datasets', await index)
print('transactions', await transactions)
print('meta', await meta)
print('summary', await summary)
print('scopes', await scopes)
print('scope values', await values)
asyncio.run(main())
Printing debug logs
By default, debug log messages are not printed. Debug logs can be enabled using the following.
import logging
logging.basicConfig(level=logging.DEBUG)
Contracts
The Script
, ScopeScript
, and QualityTestScript
abstract classes can be extended with their abstract methods
implemented to create scripts usable in other services.
The ScopeScript
in particular is intended for scripts that calculate values of certain scopes for transactions.
The QualityTestScript
is intended for scripts that check the quality of a data intake and produce a standardized
output that can be visualized and/or used by other services.
See the documentation on the abstract functions for further specifics.
Development
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
Prerequisites
- Python >= 3.9
Setup
The endpoints
module models the different PriceCypher API endpoints. Each file represents a different API and the
contents of each file are structured into the different endpoints that are provided by the API.
Similarly, each file in the models
module defines the models that are provided by the different APIs.
The SDK that this package provides is contained in the top-level package contents.
Deployment
- Execute
python -m build
to build the source archive and a built distribution. - Execute
python -m twine upload dist/*
to upload the package to PyPi.
Snapshot
To deploy a snapshot release, follow the next steps instead.
- Add
-pre
to the version insetup.cfg
. - Execute
python -m build -C--global-option=egg_info -C--global-option=--tag-build=dev
. - Execute
python -m twine upload dist/*
.
Authors
- Marijn van der Horst - Initial work
- Pieter Voors - Contracts for Script and ScopeScript
See also the list of contributors who participated in this project.
License
This project is licensed under the MIT License - see the LICENSE file for details
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
Hashes for pricecypher-sdk-0.6.0rc1.dev0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | eeebea662b0fe39edb6138d694721fc632e73eb80bc18590503c977ac0d703c3 |
|
MD5 | 240ff3f9e0c64c37a22c312dedacb431 |
|
BLAKE2b-256 | e20e645fb8281c46b2c0f29d0757daf762d238eea4ced6858b50ddcb57ff8f99 |
Hashes for pricecypher_sdk-0.6.0rc1.dev0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e5829db2b4c72c4839f8724bd7ee6348146fcd0b1e3d06ce459d6190b34d2a35 |
|
MD5 | 3b942ce2f91794384459b011e420fcba |
|
BLAKE2b-256 | 8b4959585c4d66efa3cd3a9fa2a17e571d7227252d20f7c6e4e785b933f9a9af |