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.local.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.9.6-cp313-cp313-win_amd64.whl (800.4 kB view details)

Uploaded CPython 3.13Windows x86-64

bosa_core_binary-0.9.6-cp313-cp313-manylinux_2_31_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.31+ x86-64

bosa_core_binary-0.9.6-cp313-cp313-macosx_13_0_x86_64.whl (999.0 kB view details)

Uploaded CPython 3.13macOS 13.0+ x86-64

bosa_core_binary-0.9.6-cp313-cp313-macosx_13_0_arm64.macosx_15_0_arm64.whl (836.0 kB view details)

Uploaded CPython 3.13macOS 13.0+ ARM64macOS 15.0+ ARM64

bosa_core_binary-0.9.6-cp312-cp312-win_amd64.whl (801.2 kB view details)

Uploaded CPython 3.12Windows x86-64

bosa_core_binary-0.9.6-cp312-cp312-manylinux_2_31_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.31+ x86-64

bosa_core_binary-0.9.6-cp312-cp312-macosx_13_0_x86_64.whl (996.5 kB view details)

Uploaded CPython 3.12macOS 13.0+ x86-64

bosa_core_binary-0.9.6-cp312-cp312-macosx_13_0_arm64.macosx_15_0_arm64.whl (831.1 kB view details)

Uploaded CPython 3.12macOS 13.0+ ARM64macOS 15.0+ ARM64

bosa_core_binary-0.9.6-cp311-cp311-win_amd64.whl (815.5 kB view details)

Uploaded CPython 3.11Windows x86-64

bosa_core_binary-0.9.6-cp311-cp311-manylinux_2_31_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.31+ x86-64

bosa_core_binary-0.9.6-cp311-cp311-macosx_13_0_x86_64.whl (977.5 kB view details)

Uploaded CPython 3.11macOS 13.0+ x86-64

bosa_core_binary-0.9.6-cp311-cp311-macosx_13_0_arm64.macosx_15_0_arm64.whl (810.4 kB view details)

Uploaded CPython 3.11macOS 13.0+ ARM64macOS 15.0+ ARM64

File details

Details for the file bosa_core_binary-0.9.6-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.9.6-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 1032f29ff320bb3dbbce381b26ff9c35d0ca49ca929a73607b12380f81a8ffe4
MD5 eeb7da5579bf3b4b935ed16536d15b3f
BLAKE2b-256 0a0736f5d766c9236d9c9a37bde9a8176504ffc209904c21334cc00a61dae495

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_core_binary-0.9.6-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.9.6-cp313-cp313-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.9.6-cp313-cp313-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 12fd1c4ba5f879013af36b49e8e92b8bfe0168a754e1ab6f55aa1cb714459b3b
MD5 62bb5fcca033aa7cd3e1ef5dc333913b
BLAKE2b-256 32dc508f0fd55e2ea1504dad7d378e9cc8d78359af4fc819dc5bba96acfa4fd5

See more details on using hashes here.

File details

Details for the file bosa_core_binary-0.9.6-cp313-cp313-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.9.6-cp313-cp313-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 0a79a16fe664fb67dac243cc65c3c4c40a4163882061e5bc7258b8757c4505be
MD5 b55c0e8d8685b70042686ea3d682f53b
BLAKE2b-256 59a2b670b489add085f235614974a08a2ad72e8ca62fd0e711db79a69008a351

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_core_binary-0.9.6-cp313-cp313-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.9.6-cp313-cp313-macosx_13_0_arm64.macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.9.6-cp313-cp313-macosx_13_0_arm64.macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 dc71b0fcc530c9a7dbd2ebd674314ef5252aa5299f79100ce76c0b513d518097
MD5 d282b1e1a6570c7dc5d62f822656f04a
BLAKE2b-256 8f1473016257f370f7bc8f6b0d285f2d63fba3333191a42867d1ca6b679c5668

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_core_binary-0.9.6-cp313-cp313-macosx_13_0_arm64.macosx_15_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.9.6-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.9.6-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 addd57e23028d725b48ccdab546f849c9712470115d2ef89b9af64bb3a102d1d
MD5 7c0fdfe6bddd2016c7e0b722d2184d98
BLAKE2b-256 8428b4a071df8e573c000764ab92163bf0bd0381bfdcab5827b4a0fedcb7a8e0

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_core_binary-0.9.6-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.9.6-cp312-cp312-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.9.6-cp312-cp312-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 8903489c68ce744a60e4228130304e16faf3636e64662108c5a14eb3a2af7a97
MD5 ffc241d47d490c9465fbd30397e5578c
BLAKE2b-256 d0903291d3b50320785db9943bca9b52d0fe179928e623ceb0a815bb268f35e8

See more details on using hashes here.

File details

Details for the file bosa_core_binary-0.9.6-cp312-cp312-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.9.6-cp312-cp312-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 bc56f41f1046a9e448076db207e35fdd962dfe597a5dd58e9d7011bff9410b31
MD5 87388eecee7ea766dc527cbf4b1e8b1a
BLAKE2b-256 2a8dd4b722373aad7c0b9486b74bb267a696fbc4df0bed7dd78ee94648a1e987

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_core_binary-0.9.6-cp312-cp312-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.9.6-cp312-cp312-macosx_13_0_arm64.macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.9.6-cp312-cp312-macosx_13_0_arm64.macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 c00d4cb8f33bad65231e9b90cfeeb29425dbda4807f46a521f01126b91e010a3
MD5 99731ee1d9cfa93f2129ea72239bd254
BLAKE2b-256 d6629da078b4820c514a3c22d30e1d5d9ddbc7731cb6c7028c85205a2125f34a

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_core_binary-0.9.6-cp312-cp312-macosx_13_0_arm64.macosx_15_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.9.6-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.9.6-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 bc0c0046f0825ff63d3c571687df13170d625b2c0bd2822f191ad0ad83d0a67b
MD5 c0ada2f500cdc6c62e7a7890382ec2ac
BLAKE2b-256 6df1bef411b4d31c850f4aeda6b7a295d1d624a6bdaa69b10056afb347c74c8d

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_core_binary-0.9.6-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.9.6-cp311-cp311-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.9.6-cp311-cp311-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 9d431b764162e5f1cc5cbde13d3c37f7856a4e80c27b295e79e0aa4dbd397330
MD5 bf543c0a52c9239f6b054b11933c576f
BLAKE2b-256 69893551a9e03d78241a6c3e6b688e11134dff6e35557398f5612658021a04c6

See more details on using hashes here.

File details

Details for the file bosa_core_binary-0.9.6-cp311-cp311-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.9.6-cp311-cp311-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 6c9000cf097884fd1ddad0adfb6b7be5292681e822c9510e0b708cf7c65817b2
MD5 53b6386ef719a21095ea52f8f36232ac
BLAKE2b-256 ef09db743f269ca223e16fea05f8feee18107c858f3b1bf809b94c0eb7db0584

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_core_binary-0.9.6-cp311-cp311-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.9.6-cp311-cp311-macosx_13_0_arm64.macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.9.6-cp311-cp311-macosx_13_0_arm64.macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 87a7f217b75bf0cc5d6a801377238d9a09a654cd31017235747b37f972bd6731
MD5 442c9d726fe0386555406341b35b35ed
BLAKE2b-256 b372658ec3f46abbaa920c08a50fb96cba009cc54a3c4896928a79519509c9b4

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_core_binary-0.9.6-cp311-cp311-macosx_13_0_arm64.macosx_15_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.

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