Skip to main content

Logyca

LOGYCA public libraries

Package version Python


About us


LOGYCA public libraries

  • Traversal libraries: Standard methods to be used by microservices.
  • Return codes: Standard methods for reporting result status codes using APIResult.
  • Monitoring: Standard methods to report check health status codes.
  • Helpers: Standard methods to be used. *

Source code | Package (PyPI) | Samples | Unit tests



"pip install" dependency check

The user must select the required libraries and versions for the project that uses this library, which validates that they are pre-installed in order to be installed.

To install the libraries of the logyca package (APIResult,Health) verifying the pydantic,pytz prerequisite without validating other packages, use the following command:

# Check pydantic dependency that is installed
pip install logyca

To install the fastapi package libraries and logyca authentication dependency injection, use the following command:

# Check the aiohttp dependency that is installed, for use with oauth authentication, e.g. single sign-on (SSO).
pip install logyca[oauth_token]
# Check the fastapi dependency that is installed, for use with Api-key authentication.
pip install logyca[api_key_simple_auth]
# Check the fastapi dependency that is installed, for use with Api-key and oauth authentication.
pip install logyca[oauth_token-api_key_simple_auth]

Semantic Versioning

logyca < MAJOR >.< MINOR >.< PATCH >

  • MAJOR: version when you make incompatible API changes
  • MINOR: version when you add functionality in a backwards compatible manner
  • PATCH: version when you make backwards compatible bug fixes

Definitions for releasing versions

  • https://peps.python.org/pep-0440/

    • X.YaN (Alpha release): Identify and fix early-stage bugs. Not suitable for production use.
    • X.YbN (Beta release): Stabilize and refine features. Address reported bugs. Prepare for official release.
    • X.YrcN (Release candidate): Final version before official release. Assumes all major features are complete and stable. Recommended for testing in non-critical environments.
    • X.Y (Final release/Stable/Production): Completed, stable version ready for use in production. Full release for public use.

Quick install

# Windows
python -m pip install logyca
# Linux
pip install logyca

Example of concepts using library APIResult

# Example output from ApiResult:
result={
  "resultToken": {
    "token": "",
    "refreshToken": "",
    "result": "",
    "emailActiveDirectory": "",
    "message": ""
  },
  "resultObject": [
    {
      "name": "Database server",
      "status": 0,
      "description": "Connection status fine"
    },
    {
      "name": "Redis server",
      "status": 0,
      "description": "Connection status fine"
    }
  ],
  "apiException": {
    "message": "",
    "isError": false,
    "detail": null,
    "status": 200,
    "logycaStatus": 0
  },
  "resultMessage": "",
  "dataError": false
}

Use cases: you must catch de exception

  1. if you get data only the token:
{
"dataError":false,
"resultObject":null,
"resultToken":"Not Null"
}
  1. if you get data correctly
{
"dataError":false,
"resultObject"="Not Null"
"resultToken"=null
}
  1. if you don't get because the operation was cancelled
{
"dataError":true,
"resultObject":null,
"resultToken":null,
"apiException.logycaStatus":1,
"apiException.status"=404,
"resultMessage":"exception messages: the operation was cancelled"
}

[optional]apiException.message="if needed, return an object with structured failure data other than exception messages"

Example of using library APIResult + Health Check

from fastapi.encoders import jsonable_encoder
from logyca import HealthEnum, LogycaStatusEnum, APIResultDTO, ApiFilterExceptionDTO, HTTPExceptionDTO, HealthDTO, TokensDTO
from starlette.responses import JSONResponse
import json

def example_service():
    tokensDTO=TokensDTO()
    tokensDTO.token='Token Example'

    apiFilterExceptionDTO=ApiFilterExceptionDTO()
    apiFilterExceptionDTO.isError=False
    apiFilterExceptionDTO.logycaStatus=int(LogycaStatusEnum.Already_Exists)
    apiFilterExceptionDTO.status=int(LogycaStatusEnum.Already_Exists.mappingHttpStatusCode)

    httpExceptionDTO=HTTPExceptionDTO()
    httpExceptionDTO.detail='No Problem'

    listHealth=[]

    listHealth.append(HealthDTO(name='Check CPU',status=HealthEnum.Ok,description='OK').__dict__)
    listHealth.append(HealthDTO(name='Check Connect DB',status=HealthEnum.Warning,description='Warning').__dict__)
    listHealth.append(HealthDTO(name='Check Connect Storage',status=HealthEnum.Critical,description='Critical').__dict__)

    apiResultDTO=APIResultDTO()
    apiResultDTO.resultMessage=httpExceptionDTO.detail
    apiResultDTO.resultObject=listHealth
    apiResultDTO.dataError=False
    apiResultDTO.resultToken=tokensDTO
    apiResultDTO.apiException=apiFilterExceptionDTO

    return apiResultDTO

def simulator_api_return():
    apiResultDTO = example_service()
    content = jsonable_encoder(apiResultDTO)
    print((json.dumps(content,indent=4)))
    return JSONResponse(content=content,status_code=200)

simulator_api_return()

# output sample
  #
  # {
  #     "resultToken": {
  #         "token": "Token Example",
  #         "refreshToken": "",
  #         "result": "",
  #         "emailActiveDirectory": "",
  #         "message": ""
  #     },
  #     "resultObject": [
  #         {
  #             "name": "Check CPU",
  #             "status": 0,
  #             "description": "OK"
  #         },
  #         {
  #             "name": "Check Connect DB",     
  #             "status": 1,
  #             "description": "Warning"        
  #         },
  #         {
  #             "name": "Check Connect Storage",
  #             "status": 2,
  #             "description": "Critical"       
  #         }
  #     ],
  #     "apiException": {
  #         "message": "",
  #         "isError": false,
  #         "detail": null,
  #         "status": 409,
  #         "logycaStatus": 6
  #     },
  #     "resultMessage": "No Problem",
  #     "dataError": false
  # }

Example of using helpers

from logyca import buildUrl,convertDateTimeStampUTCtoUTCColombia

url1='https://domain.com'
url2='api/get'
print(f'buildUrl={buildUrl(url1,url2)}')
# ouput
# buildUrl=https://domain.com/api/get

datetimestampUTC=1679729109
print(f'datetimeUTCColombia={convertDateTimeStampUTCtoUTCColombia(datetimestampUTC)}')
# output
# datetimeUTCColombia=2023-03-25 02:25:09-05:00

Example of using Logger

At the root of the project, the logs folder is created and the types of errors are differentiated by different files.

# main.py
from logyca import Logger, ConstantsLogger
logger = Logger(logger_name=ConstantsLogger.NAME,log_dir=FOLDER_LOGS,log_file_name=f"{App.Settings.NAME}")
logger.info(f"message")

# Other files.py
from logyca import Logger, ConstantsLogger
import logging
logger = logging.getLogger(ConstantsLogger.NAME)

logger.info(f"message")
logger.error(f"message")

Current library test

# Library installation

# Windows
python -m pip install logyca[test]
# Linux
pip install logyca

# Run it
pytest -s

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

Types of changes

  • Added for new features.
  • Changed for changes in existing functionality.
  • Deprecated for soon-to-be removed features.
  • Removed for now removed features.
  • Fixed for any bug fixes.
  • Security in case of vulnerabilities.

[0.1.9] - 2024-05-21

Added

  • New logger functionality.
  • new authentication functionality in fastapi by dependency injection with api-key, to be used on endpoints.
  • new authentication functionality in fastapi by dependency injection with oauth (single sign on), to be used on endpoints.
  • In the samples folder of this library, there are complete working examples of using the code.

[0.1.8] - 2023-10-03

Fixed

  • Due to a link error in the readme to internal documents in pypi, we chose to leave the changelog at the end of the readme.

[0.1.7] - 2023-10-02

Fixed

  • The url address for the logyca logo is corrected
  • Adjust return code for LogycaStatusEnum class: LogycaStatusEnum.Created==HTTPStatus.CREATED
  • Adjust return code for LogycaStatusEnum class: LogycaStatusEnum.InProcess==HTTPStatus.ACCEPTED
  • Adjust return code for LogycaStatusEnum class: LogycaStatusEnum.Partial==HTTPStatus.ACCEPTED
  • Empty files init.py removed

[0.1.6] - 2023-09-11

Fixed

  • Pydantic restriction for versions lower than 2.0 is removed

[0.1.5] - 2023-03-27

Added

  • Release ready for production

[0.1.6-9] - 2024-5-21<

Added

  • new features such as: logging, helpers for fastapi

[0.1.10] - 2024-05-23

Added

  • Documentation improvements.
  • Documentation integrated with github

[0.1.11] - 2024-05-24

Deprecated

  • add print info deprecated in convert_string_to_boolean()

Added

  • new parse_bool() function that will replace convert_string_to_boolean()

[0.1.12-13] - 2024-06-13

Fixed

  • Oauth fix

[0.1.13] - 2024-06-20

Added

  • New Logger feature to rotate backup logs and allow them to be written.

[0.1.14] - 2024-07-02

Added

  • New APIResultDTOExternal feature to Scheme output

[0.1.15] - 2024-07-05

Fixed

  • Updated LogycaStatusEnum for starlette library use
  • Correction of exception handlers.

[0.1.16] - 2024-07-12

Added

  • For object classes like APIResultDTO and others, the to_dict() function is added to be able to serialize the attributes to json in a simple way.
  • Added object serialization example.

[0.1.17] - 2024-07-22

Fixed

  • APIResultDTO fixes the data=False error external of the init constructor.

[0.1.18] - 2024-08-16

Fixed

  • Example of auth apkey with dockerfile and dependencies that were missing when installing the library is added.

[0.1.19] - 2025-01-02

Added

  • To the from logyca import APIKeyScheme, APIKey functionality to validate an endpoint api_key: str = Depends(get_api_key), the ability to choose the name of the api key is added, by default the value is "x-api-key". To change the name you must configure the environment variable API_KEY_NAME. Example: os.environ["API_KEY_NAME"] = "x-api-key-other-value".

Metadata

Release files for logyca 0.1.19

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for logyca 0.1.19
File Size Uploaded Provenance
logyca-0.1.19.tar.gz 22.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for logyca 0.1.19
File Interpreter ABI Platform
logyca-0.1.19-py3-none-any.whl Python 3 none any Details

Total release size: 45.7 kB

Release files / logyca-0.1.19.tar.gz

Download URL logyca-0.1.19.tar.gz
Size 22.3 kB
Tags Source
SHA-256 checksum
How to use checksums
cc52df3baba185ced7eacde12ac0d51b5df00e9f49810cd3725d64b049b98b6f
BLAKE2b-256 checksum
How to use checksums
f18bc312060f2cff9573e0b0ccba513a11ba95f1c4e88d9c1706dda2fb6adfaf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.11.9

Release files / logyca-0.1.19-py3-none-any.whl

Download URL logyca-0.1.19-py3-none-any.whl
Size 23.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3976423275418dc77c3f9a640f37435fb436c5d6b86751ae7f9329f05ad69a3c
BLAKE2b-256 checksum
How to use checksums
04b28741ba80f48d03dc9c2e0aeeebcb4c6fbe8ce8e679cb26354f2f9cce4b0e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.11.9

Security for logyca 0.1.19

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.19 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page