Skip to main content

Collect data from django models into ElasticSearch

Project description

django-olympus

[![build-status-image]][build-status] [![coverage-status-image]][codecov] [![pypi-version]][pypi]

Collect data from django models into ElasticSearch.

This Django application provides a OlympusCollector class that is a wrapper for the ElasticSearch API and database (using their official package).

To know more about how to use it, please check the Setup section.

Setup

After adding django-olympus as part of your required packages, add olympus to INSTALLED_APPS in your settings.py.

The following settings are available for customization:

Name Default Description
OLYMPUS_ELASTICSEARCH_URL None This should point to the ElasticSearch server running.
OLYMPUS_ELASTICSEARCH_VERIFY_CERTS None This should tell whether certificates should be verified - only set this to false for local development

Since this application provides a baseline Collector class, this will help you bootstrap data collectors to send information to ElasticSearch. The following section details how to write your own collectors.

Collectors

To create your own collector, in any Django app of your project, extend the OlympusCollector class and implement the collect method to specify all the logic you need.

#myapp/occ.py
from olympus.base import OlympusCollector


class SampleCollector(OlympusCollector):
    index_name = "sample_collector"  # can be anything you'd like.
    index_date_pattern = "%Y.%m.%d"  # can be anything you'd like.
    index_lifecycle_name = "something"  # if you use default lifecycle policies and would like to assign a different one.

    def collect(self):
        self.logger.info(f"started {self.index_name}")  # Base class provides built-in logging.

        data = some_func()  # Some logic to retrieve data, either from API, from Django's Database or whatever.

        yield = {
            "_id": "1",  # _id is mandatory and can be anything, really, as long as it is unique.
            "some": data.attribute,
            "more": data.attribute2,
        }

To keep collectors organized, you might want to create an occ.py file in each app, implementing the collectors. Each app can implement as many collectors as necessary, there is really no restrictions.

olympus API provides a Django command called push_to_es which allows you to run a collector. To run the sample above, ./manage.py push_to_es myapp.SampleCollector would be required.

Apps with collectors must be part of your settings.py file, otherwise collectors are not initialized and not added to the list - hence push_to_es will fail.

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

django_olympus-0.0.6.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_olympus-0.0.6-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file django_olympus-0.0.6.tar.gz.

File metadata

  • Download URL: django_olympus-0.0.6.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for django_olympus-0.0.6.tar.gz
Algorithm Hash digest
SHA256 692da153e62787acb97a4bcce2d92f632518eb3fed8b7957725f3cbcaa77d179
MD5 a41a01de1b51d5a610620f3725a8b009
BLAKE2b-256 06c4168059e3981e4b4a7760978a3d56100c0c1a502f29b67c69421ffe123ff8

See more details on using hashes here.

File details

Details for the file django_olympus-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: django_olympus-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for django_olympus-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 0edbb06951b77e891fa67d6a0e34bd4eb2002f98a7821801ee6de2d65537993a
MD5 dabd7f73bc8307bd493c7e3dcb3b4788
BLAKE2b-256 1bc66d049e084c48d35cd8b2d100b0e1b24cfefb5d8486e390f9fc242e0d0846

See more details on using hashes here.

Supported by

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