Skip to main content

Python starter service

Project description

python-starter-service

This is a starter service project template. Use this template to create a new service project.

python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt # Or instead of `pip`, use `pip3`

Getting started

First you need to provide ENV variables for the service to run.

ENV variables

Main ENV variables:

  • CLIENT_ID - client id of the service
  • REST_API_ENABLED - enable/disable REST API (default: true)

Kafka

  • CONSUME - comma separated list of topics to consume
  • PRODUCE - comma separated list of topics to produce
  • KAFKA_HOST - Kafka host
  • SCHEMA_REGISTRY - schema registry host
  • MAX_POLL_INTERVAL_MS - max poll interval in ms (default: 600000)
  • SESSION_TIMEOUT_MS - session timeout in ms (default: 600000)

Usage

Check the provided examples in the examples folder.

Example

from starter_service import StarterService

class ExampleService(StarterService):

    def health(self):
        """ Health check endpoint """
        return "OK"

    def ready(self):
        """ Ready check endpoint """    
        return True

    def process(self, message):
        """ Process message """

    @API.post(consumer="article_raw_en", producer="metadata_item_key_en", doc="Process raw article and return metadata")
    def handle_message(self, message: dict):
        """ Process raw article and return metadata """
        return {
            "articleId": message['id'],
            "origin": "string",
            "data": [
                {
                    "type": "string",
                    "value": "string",
                    "confidence": 0,
                    "metadata": {
                        "string": "string"
                    }
                }
            ]
        }

    if __name__ == '__main__':
        ExampleService()

Uploading to PyPi

  1. Ensure you have the necessary tools installed: Make sure you have setuptools and wheel installed. You can install them using pip:
# Build the distribution files: In the root directory of your project, run the following command to build the distribution files (wheel and source distribution):
pip install setuptools wheel twine
  1. Build the distribution files: In the root directory of your project, run the following command to build the distribution files (wheel and source distribution):
# This command will generate the distribution files inside the dist directory.
# Remember to FIRST update the version number in your `setup.py` file for each new release to avoid conflicts.
python setup.py sdist bdist_wheel

This command will generate the distribution files inside the dist directory.

  1. Register an account on PyPI: If you haven't done so already, create an account on PyPI and verify your email address.

  2. Upload the package to PyPI: Use twine to upload the distribution files to PyPI:

# This command will prompt you to enter your PyPI username and password. Once provided, twine will upload the distribution files to PyPI.
twine upload dist/*

This command will prompt you to enter your PyPI username and password. Once provided, twine will upload the distribution files to PyPI.

  1. Verify the package on PyPI: Visit your package page on PyPI to ensure that the package has been successfully uploaded and published.

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

osint-python-starter-service-2.3.0.tar.gz (14.9 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file osint-python-starter-service-2.3.0.tar.gz.

File metadata

File hashes

Hashes for osint-python-starter-service-2.3.0.tar.gz
Algorithm Hash digest
SHA256 6c5c23e303569c723456f7080f10360c93371991920eb8d1c3ad4f009f9e7b94
MD5 b84cb8853d3561cd7c287b8d0854cfe6
BLAKE2b-256 0ed880833ba12e283d828346ac43e8b6f784ab03855a393e110eb411c948e8c2

See more details on using hashes here.

File details

Details for the file osint_python_starter_service-2.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for osint_python_starter_service-2.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 298f42319db6868b2cbc71d95fc66dd1699a58c20275f9803e81c4fdf982ca8d
MD5 84879df65525200d8972a9d99f2418ef
BLAKE2b-256 a4b70bd72df897a58747051f08ec7e521525482744ec59b8378abf92245d4359

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