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 serviceREST_API_ENABLED
- enable/disable REST API (default:true
)
Kafka
CONSUME
- comma separated list of topics to consumePRODUCE
- comma separated list of topics to produceKAFKA_HOST
- Kafka hostSCHEMA_REGISTRY
- schema registry hostMAX_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
- Ensure you have the necessary tools installed: Make sure you have
setuptools
andwheel
installed. You can install them usingpip
:
# 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
- 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.
-
Register an account on PyPI: If you haven't done so already, create an account on PyPI and verify your email address.
-
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.
- Verify the package on PyPI: Visit your package page on PyPI to ensure that the package has been successfully uploaded and published.
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
File details
Details for the file osint-python-starter-service-2.3.0.tar.gz
.
File metadata
- Download URL: osint-python-starter-service-2.3.0.tar.gz
- Upload date:
- Size: 14.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c5c23e303569c723456f7080f10360c93371991920eb8d1c3ad4f009f9e7b94 |
|
MD5 | b84cb8853d3561cd7c287b8d0854cfe6 |
|
BLAKE2b-256 | 0ed880833ba12e283d828346ac43e8b6f784ab03855a393e110eb411c948e8c2 |
File details
Details for the file osint_python_starter_service-2.3.0-py3-none-any.whl
.
File metadata
- Download URL: osint_python_starter_service-2.3.0-py3-none-any.whl
- Upload date:
- Size: 23.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 298f42319db6868b2cbc71d95fc66dd1699a58c20275f9803e81c4fdf982ca8d |
|
MD5 | 84879df65525200d8972a9d99f2418ef |
|
BLAKE2b-256 | a4b70bd72df897a58747051f08ec7e521525482744ec59b8378abf92245d4359 |