Skip to main content

BOSA Core Library

Project description

BOSA Core

BOSA Core is a flexible plugin-based architecture that allows you to build modular and extensible applications. It provides a robust framework for managing plugins, handling dependencies, and injecting services.

Key Features

  • 🔌 Plugin-based Architecture
  • 💉 Dependency Injection
  • 🔄 Service Registry
  • 🛠️ Flexible Plugin Handlers
  • 🌐 HTTP Interface Support
  • 📊 OpenTelemetry Integration
  • 🛡️ Sentry Error Tracking
  • 📜 Logging

Installation

Prerequisites

1. Installation from Pypi

Choose one of the following methods to install the package:

Using pip

pip install bosa-core-binary

Using Poetry

poetry add bosa-core-binary

2. Development Installation (Git)

For development purposes, you can install directly from the Git repository:

poetry add "git+ssh://git@github.com/GDP-ADMIN/bosa-sdk.git#subdirectory=python/bosa-core"

Plugin Architecture Overview

Plugin Architecture

How It Works

  1. Plugin Manager: The central piece that orchestrates everything

    • Manages plugin lifecycle
    • Handles service registration
    • Initializes plugins with required dependencies
  2. Service Registry: A container for all services

    • Stores service instances
    • Handles dependency injection
    • Maps service types to their implementations
    • Note: You don't need to create your own Service Registry - it's integrated into the Manager!
  3. Plugin Handler: Interface for providing services to plugins

    • Creates service injections through create_injections
    • Initializes plugin-specific resources
    • Can be extended for different types of plugins (e.g., HTTP handlers)
  4. Plugin: Base class for all plugins

    • Has basic metadata (name, description, version)
    • Receives injected services automatically
    • Can be extended with specific functionality
  5. Open Telemetry: Initializer class to use open telemetry

    • Integrates with OpenTelemetry for tracing and metrics
    • Provides observability for plugins and services
    • Can be configured to export data to various backends (e.g., Jaeger, Prometheus)
  6. Sentry: Initializer class to use sentry

    • Integrates with Sentry for error tracking and performance monitoring
    • Captures exceptions and sends them to Sentry
    • Provides insights into application performance and errors

Authentication

BOSA Core provides a robust, multi-tenancy authentication system, allowing secure client and user management.

  1. Client Management:

    • Clients are created using a Master Key (BOSA_WHITELISTED_KEYS).
    • Each client has a unique API key used for authentication.
    • API Key Format: sk-client-<base64-client-id>.<base64-client-name>.<client-secret>.
    • Clients can manage their users and authentication settings.
  2. User Authentication:

    • Clients create users by providing an identifier.
    • Each user receives a secret, which is displayed only once.
    • Users authenticate using their identifier and secret.
    • User API Key Format: sk-user-<base64-user-id>.<base64-user-identifier>.<user-secret>.
  3. Token-Based Access:

    • Upon authentication, users receive JWT tokens for secure access.
    • Tokens are verified for subsequent requests.
    • Tokens expire after 30 days (default: 43,200 minutes).
    • Tokens can be revoked when necessary.
  4. Third-Party Integrations:

    • Users can create integrations with third-party services.
    • Authentication credentials are securely stored.
    • Each integration can be assigned scoped access.

For detailed implementation, refer to the Authentication README.

Implementation Details

The plugin system works through these key components:

1. Plugin Manager

from fastapi_interface import FastApiHttpInterface

# Create FastAPI handler
fastapi_handler = FastApiHttpInterface()

# Initialize manager with the handler
manager = PluginManager(handlers=[fastapi_handler])
manager.register_plugin(MyPlugin)
  • Initializes the plugin system
  • Manages plugin lifecycle
  • Handles service registration

2. Plugin Handler

from bosa_core.plugin import PluginHandler

class MyHandler(PluginHandler):
    @classmethod
    def create_injections(cls, instance):
        # Tell the manager what services this handler provides
        return {MyService: instance}

    @classmethod
    def initialize_plugin(cls, instance, plugin):
        # Initialize plugin resources
        pass
  • Creates service mappings via create_injections
  • Initializes plugin resources
  • Can be customized for different plugin types

3. Plugin

from bosa_core.plugin import Plugin
from fastapi_interface import FastApiService

class MyPlugin(Plugin):
    # Services will be injected automatically
    fastapi_service: FastApiService

    def __init__(self, name, description, version):
        super().__init__(name, description, version)
  • Base class for all plugins
  • Receives injected services
  • Can be extended with custom functionality

4. Open telemetry external exporter (enable fastapi & langchain instrumentation)

from bosa_core.telemetry import OpenTelemetryConfig, FastAPIConfig, init_telemetry
from fastapi import FastAPI

endpoint = "your-exporter-endpoint"
port = "your-exporter-port"
attributes = {
   "key1":"val1"
}
app = FastAPI()
use_langchain_instrumentation = True
fastapi_config = FastAPIConfig(app=app)
otel_config = OpenTelemetryConfig(endpoint=endpoint, port=port, attributes=attributes, fastapi_config=fastapi_config, use_langchain=use_langchain_instrumentation)
init_telemetry(TelemetryConfig(otel_config=otel_config))

5. Sentry

from bosa_core.telemetry import SentryConfig, init_telemetry

def traces_sampler(sampling_context: dict) -> float:
    """Determine appropriate sampling rate for Sentry transactions.
    Args:
        sampling_context: Context dictionary containing transaction information
    Returns:
        float: Sampling rate between 0 and 1
    """

    ### you can use customization (ex: for certain name sampler will be 0.1) for trace_sampler in this class
    return 1.0


dsn = "your-dsn"
environment = "development/staging/production"
release = "your release tag"
sentry_config = SentryConfig(
        dsn=dsn,
        environment=environment,
        release=release,
        traces_sampler=traces_sampler,
        send_default_pii=True,
    )
init_telemetry(TelemetryConfig(sentry_config=sentry_config))

6. Sentry with Open Telemetry (enable fastapi & langchain instrumentation)

from bosa_core.telemetry import SentryConfig, init_telemetry, FastAPIConfig, OpenTelemetryConfig
from fastapi import FastAPI


def traces_sampler(sampling_context: dict) -> float:
    """Determine appropriate sampling rate for Sentry transactions.
    Args:
        sampling_context: Context dictionary containing transaction information
    Returns:
        float: Sampling rate between 0 and 1
    """

    ### you can use customization (ex: for certain name sampler will be 0.1) for trace_sampler in this class
    return 1.0


dsn = "your-dsn"
environment = "development/staging/production"
release = "your release tag"

attributes = {
   "key1":"val1"
}
app = FastAPI()
use_langchain_instrumentation = True
fastapi_config = FastAPIConfig(app=app)
opentelemetry_init = OpenTelemetryConfig(attributes=attributes, fastapi_config=fastapi_config, use_langchain=use_langchain_instrumentation)

sentry_config = SentryConfig(
        dsn=dsn,
        environment=environment,
        release=release,
        traces_sampler=traces_sampler,
        send_default_pii=True,
        open_telemetry_initiliazer=opentelemetry_init
    )
init_telemetry(sentry_config=sentry_config)

7. Logging Ner API Handler

from bosa_core.logger import init_ner_pii_logging_handler

init_ner_pii_logging_handler(logger_name="logging-name", api_url="https://dev-api-gdplabs-ner-api.obrol.id/anonymize", api_field="text", pii_ner_process_enabled=True)


logger.info("contoh nomor ktp 3525011212941001\ncontoh email john.doe@example.com\ncontoh nomor telepon +628121729819 dan 0812898029384.\ncontoh npwp 01.123.456.7-891.234" ) # if you using gdplabs ner API output will be contoh nomor ktp <ID_KTP_1>\ncontoh email <EMAIL_ADDRESS_1>\ncontoh nomor telepon <PHONE_NUMBER_1> dan <PHONE_NUMBER_2>.\ncontoh npwp <ID_NPWP_1>

[!WARNING] If you are using Logger Ner API handler, the logging process may take some time because it needs to call an API for every log entry synchronously.

8. Logging Regex Handler

from bosa_core.logger import init_regex_pii_logging_handler

init_regex_pii_logging_handler(logger_name="logging-name", pii_regex_process_enabled=True)


logger.info("contoh nomor ktp 3525011212941001\ncontoh email john.doe@example.com\ncontoh nomor telepon +628121729819 dan 0812898029384.\ncontoh npwp 01.123.456.7-891.234" ) # if you using gdplabs ner API output will be contoh nomor ktp <ID_KTP_1>\ncontoh email <EMAIL_ADDRESS_1>\ncontoh nomor telepon <PHONE_NUMBER_1> dan <PHONE_NUMBER_2>.\ncontoh npwp <ID_NPWP_1>

Getting Started

  1. Install dependencies:

    poetry install
    
  2. Create a plugin:

    class MyPlugin(Plugin):
        name = "my-plugin"
        description = "My awesome plugin"
        version = "1.0.0"
    
  3. Register and use:

    # Using FastAPI as an example
    from fastapi import FastAPI
    from fastapi_interface import FastApiHttpInterface
    
    app = FastAPI()
    fastapi_handler = FastApiHttpInterface(app)
    manager = PluginManager(handlers=[fastapi_handler])
    manager.register_plugin(MyPlugin)
    

Development

  • Use Poetry for dependency management
  • Install pre-commit hooks poetry run pre-commit install. This will run checks before each commit.
  • Run ./build.sh to perform all checks:
    • Code formatting and validation (ruff)
    • Documentation style (pydocstyle)
    • Tests (pytest)
    • And more!

References

Product Requirements Documents(PRD):

  • N/A

Architecture Documents:

Design Documents:

Implementation Documents:

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 Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

bosa_core_binary-0.5.1b2-cp313-cp313-win_amd64.whl (638.7 kB view details)

Uploaded CPython 3.13Windows x86-64

bosa_core_binary-0.5.1b2-cp313-cp313-manylinux_2_31_x86_64.whl (950.6 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.31+ x86-64

bosa_core_binary-0.5.1b2-cp313-cp313-macosx_11_0_universal2.macosx_13_0_arm64.whl (637.3 kB view details)

Uploaded CPython 3.13macOS 11.0+ universal2 (ARM64, x86-64)macOS 13.0+ ARM64

bosa_core_binary-0.5.1b2-cp313-cp313-macosx_10_13_universal2.macosx_13_0_x86_64.whl (731.6 kB view details)

Uploaded CPython 3.13macOS 10.13+ universal2 (ARM64, x86-64)macOS 13.0+ x86-64

bosa_core_binary-0.5.1b2-cp312-cp312-win_amd64.whl (643.1 kB view details)

Uploaded CPython 3.12Windows x86-64

bosa_core_binary-0.5.1b2-cp312-cp312-manylinux_2_31_x86_64.whl (951.4 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.31+ x86-64

bosa_core_binary-0.5.1b2-cp312-cp312-macosx_11_0_universal2.macosx_13_0_arm64.whl (636.4 kB view details)

Uploaded CPython 3.12macOS 11.0+ universal2 (ARM64, x86-64)macOS 13.0+ ARM64

bosa_core_binary-0.5.1b2-cp312-cp312-macosx_10_9_universal2.macosx_13_0_x86_64.whl (728.0 kB view details)

Uploaded CPython 3.12macOS 10.9+ universal2 (ARM64, x86-64)macOS 13.0+ x86-64

bosa_core_binary-0.5.1b2-cp311-cp311-win_amd64.whl (643.8 kB view details)

Uploaded CPython 3.11Windows x86-64

bosa_core_binary-0.5.1b2-cp311-cp311-manylinux_2_31_x86_64.whl (861.0 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.31+ x86-64

bosa_core_binary-0.5.1b2-cp311-cp311-macosx_11_0_universal2.macosx_13_0_arm64.whl (619.7 kB view details)

Uploaded CPython 3.11macOS 11.0+ universal2 (ARM64, x86-64)macOS 13.0+ ARM64

bosa_core_binary-0.5.1b2-cp311-cp311-macosx_10_9_universal2.macosx_13_0_x86_64.whl (719.9 kB view details)

Uploaded CPython 3.11macOS 10.9+ universal2 (ARM64, x86-64)macOS 13.0+ x86-64

File details

Details for the file bosa_core_binary-0.5.1b2-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.5.1b2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 d62a135a361e29d845cfe3e913bf41c3c02637feca8a6c60c497162bd5b5092b
MD5 883b5936f75849894d62f4e4d96f06e4
BLAKE2b-256 58cebe35ee4ca9e1c3144dd36fed49d48d8ff0342412d4479a29cacfbd0663cb

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_core_binary-0.5.1b2-cp313-cp313-win_amd64.whl:

Publisher: build-binary.yml on GDP-ADMIN/bosa-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bosa_core_binary-0.5.1b2-cp313-cp313-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.5.1b2-cp313-cp313-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 ce6c1769dc66e7782991c1c05d4e3b33bc1b01162b0ef5c2ed0161c7dc2c9c70
MD5 5bba28f9f7d836a44babfd206b18ee33
BLAKE2b-256 2f5d23d99aad32dd4cf9747b5f42e94c8a7d857612bc4e5886c021dff05ad9a1

See more details on using hashes here.

File details

Details for the file bosa_core_binary-0.5.1b2-cp313-cp313-macosx_11_0_universal2.macosx_13_0_arm64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.5.1b2-cp313-cp313-macosx_11_0_universal2.macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 5c5f9abad955b4adfd70eb4cf8f5c38d0220175d2f65ea555860a5e0d78ecc5d
MD5 7f46e15f05dfd2438c5b7102a69fe1e5
BLAKE2b-256 eb4f0a82c7481609832f4c849b320a325bf6d666f687f687ba5ba7f3c9fbc25a

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_core_binary-0.5.1b2-cp313-cp313-macosx_11_0_universal2.macosx_13_0_arm64.whl:

Publisher: build-binary.yml on GDP-ADMIN/bosa-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bosa_core_binary-0.5.1b2-cp313-cp313-macosx_10_13_universal2.macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.5.1b2-cp313-cp313-macosx_10_13_universal2.macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 1c5c355428be5461c3f22417c01d93fe2184357f31deb49d14fcae08af558888
MD5 a7d06bc4192c9bd67739c13e95817c51
BLAKE2b-256 98d7fa32e9b6cd8eecc83e4dfaf563b24e1161b63ce297537112507cfac988f6

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_core_binary-0.5.1b2-cp313-cp313-macosx_10_13_universal2.macosx_13_0_x86_64.whl:

Publisher: build-binary.yml on GDP-ADMIN/bosa-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bosa_core_binary-0.5.1b2-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.5.1b2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 93f29f60cb8c0a0ac60c65708719a0402b5b9e5a7646b84e44c81b6d41ff2c3b
MD5 d5d7f51891d51a9bec84010c8199ab7d
BLAKE2b-256 309aae710637ddfbbf957cc407b3e92ce0d1382c5e0d11646bcf08a9b766492b

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_core_binary-0.5.1b2-cp312-cp312-win_amd64.whl:

Publisher: build-binary.yml on GDP-ADMIN/bosa-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bosa_core_binary-0.5.1b2-cp312-cp312-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.5.1b2-cp312-cp312-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 7e926d4f970f3be96052d67968d274b9217394b4b9d465d7373eed6a93d54649
MD5 1427e3ff64a9616c211d23a59a456c68
BLAKE2b-256 3b4ae5fda907da620b42d5d92d68ec8f3b65fff6081395e4ca8e973103314086

See more details on using hashes here.

File details

Details for the file bosa_core_binary-0.5.1b2-cp312-cp312-macosx_11_0_universal2.macosx_13_0_arm64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.5.1b2-cp312-cp312-macosx_11_0_universal2.macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 979b772074018c1e14114040b09b20f3edac7990ff0e5d014b4c200dde0c835e
MD5 cf842e78d8d7044142837eb958e4ca34
BLAKE2b-256 39e115ea8c6d1c160d3cf49a06c1b6386f0f4f21cf0a7fe2fe3e2b1ec0ca5b94

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_core_binary-0.5.1b2-cp312-cp312-macosx_11_0_universal2.macosx_13_0_arm64.whl:

Publisher: build-binary.yml on GDP-ADMIN/bosa-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bosa_core_binary-0.5.1b2-cp312-cp312-macosx_10_9_universal2.macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.5.1b2-cp312-cp312-macosx_10_9_universal2.macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 07e859aa5a3e310f876c3a46a7761e7cfaf9dda8d3f4724bcd8fefc21e906a99
MD5 42285df8edeec055bd08448cfb515a89
BLAKE2b-256 c245999ce5818ae6290903f0a75b88cc4bcd35f666c136b10e9228a9f1789c72

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_core_binary-0.5.1b2-cp312-cp312-macosx_10_9_universal2.macosx_13_0_x86_64.whl:

Publisher: build-binary.yml on GDP-ADMIN/bosa-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bosa_core_binary-0.5.1b2-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.5.1b2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 e1101e6d24d96bcfb9c26c6a9f22841883c01ba47dcc57e071fe429f0fc87f60
MD5 98cdd0cf1ed32a6973ff3eae3040137e
BLAKE2b-256 41fa54a9d58666690a3258821b28871f59adeaa8044d31a6ae34c9ddbd3d1bb3

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_core_binary-0.5.1b2-cp311-cp311-win_amd64.whl:

Publisher: build-binary.yml on GDP-ADMIN/bosa-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bosa_core_binary-0.5.1b2-cp311-cp311-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.5.1b2-cp311-cp311-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 a7e78ba93d0ec53beb74b00ea497d895613cef38894ce3e980b98ee5bb2499a6
MD5 ac90b19de2169f325647bd73a1c8de2b
BLAKE2b-256 a697c198080b3ec4dadd8fcf5f1db08018e4f10bfe506e51eb2b6916034105e3

See more details on using hashes here.

File details

Details for the file bosa_core_binary-0.5.1b2-cp311-cp311-macosx_11_0_universal2.macosx_13_0_arm64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.5.1b2-cp311-cp311-macosx_11_0_universal2.macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 4bc92d47d6af6842614efc090fb32b25fbe932874f6f74744865bb3c1f5a2f87
MD5 6561a615812d32c265b1f9ae84a180d8
BLAKE2b-256 ac78aacdcab29ff330415207eaa1326c2071ebc2c7843a8a06e1aacba9b46350

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_core_binary-0.5.1b2-cp311-cp311-macosx_11_0_universal2.macosx_13_0_arm64.whl:

Publisher: build-binary.yml on GDP-ADMIN/bosa-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bosa_core_binary-0.5.1b2-cp311-cp311-macosx_10_9_universal2.macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.5.1b2-cp311-cp311-macosx_10_9_universal2.macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 cb8421d73b90b5cd14c3c11f89bc2f66d691982c64b900de4aa2f766a0e9283b
MD5 da556e4fc805495df4a070b50a36be94
BLAKE2b-256 25a1d847fd8fac8de5bcdd45a8bc749ac09760ed14a27376957333529475944d

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_core_binary-0.5.1b2-cp311-cp311-macosx_10_9_universal2.macosx_13_0_x86_64.whl:

Publisher: build-binary.yml on GDP-ADMIN/bosa-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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