Skip to main content

A library with classes and types used througout the backend for Conflict Cartographer

Project description

CC Backend Library

Build

This library contains several classes and data models that are useful when writing services that interact with other services in Conflict Cartographer. In particular, the modules api_client and schema respectively provide classes for retrieving and modelling data from APIs.

Data retrieval

Data retrieval is offered via the cc_backend_lib.dal.Dal class. This class is instantiated by passing several API clients:

from cc_backend_lib.clients import predictions_client, scheduler_client, users_client, countries_client
from cc_backend_lib import dal

cc_dal = dal.Dal(
      predictions = predictions_client.PredictionsClient(...),
      scheduler = scheduler_client.SchedulerClient(...),
      users = users_client.UsersClient(...),
      countries = countries_client.CountriesClient(...),
   )

The class has several methods that offer access to data and summaries. See help(Dal). The .participation_summary method caches results for past (shift < 0) time-periods for efficiency.

Caching

A powerful caching decorator is provided that lets you decorate both sync and async functions for caching. For using different kinds of backends or for other kinds of customization (LRU, etc.), the caching decorator lets you pass a custom cache class. There are some provided cache classes, including one that uses Redis:

from cc_backend_lib.cache import redis_cache, cache

@cache.cache(redis_cache.RedisBackend, host = "...", expiry_time = 100)
def my_slow_function(a,b,c):
   ...

# First time slow
a = my_slow_function(1,2,3)

# Second time fast
b = my_slow_function(1,2,3)

assert a == b

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

cc_backend_lib-0.13.0.tar.gz (13.8 kB view details)

Uploaded Source

Built Distribution

cc_backend_lib-0.13.0-py3-none-any.whl (22.1 kB view details)

Uploaded Python 3

File details

Details for the file cc_backend_lib-0.13.0.tar.gz.

File metadata

  • Download URL: cc_backend_lib-0.13.0.tar.gz
  • Upload date:
  • Size: 13.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.12

File hashes

Hashes for cc_backend_lib-0.13.0.tar.gz
Algorithm Hash digest
SHA256 cd624db90f90a7c8e94b1a1706c8a77f61cabc535fbff6dd66d1221bf85ffe71
MD5 3bf3c59cd296a07980b3ac1f68ed56db
BLAKE2b-256 04e5925d951fbba6f65fb309dd3594272385187d61d49002b76fa43df438dc02

See more details on using hashes here.

File details

Details for the file cc_backend_lib-0.13.0-py3-none-any.whl.

File metadata

  • Download URL: cc_backend_lib-0.13.0-py3-none-any.whl
  • Upload date:
  • Size: 22.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.12

File hashes

Hashes for cc_backend_lib-0.13.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0f76775d0f2116f8758300ff449e2f25861e27646e29133dca89a047a29e30f1
MD5 004bb7a475f7b3a14d19dccfae1e2e56
BLAKE2b-256 2cad4cc2fd43acaee626ae36e610822f2ee5a21da90a10d1430e1b011b05f91d

See more details on using hashes here.

Supported by

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