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.8.0-cp313-cp313-win_amd64.whl (684.9 kB view details)

Uploaded CPython 3.13Windows x86-64

bosa_core_binary-0.8.0-cp313-cp313-manylinux_2_31_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.31+ x86-64

bosa_core_binary-0.8.0-cp313-cp313-macosx_13_0_x86_64.whl (829.2 kB view details)

Uploaded CPython 3.13macOS 13.0+ x86-64

bosa_core_binary-0.8.0-cp313-cp313-macosx_13_0_arm64.macosx_15_0_arm64.whl (693.9 kB view details)

Uploaded CPython 3.13macOS 13.0+ ARM64macOS 15.0+ ARM64

bosa_core_binary-0.8.0-cp312-cp312-win_amd64.whl (690.3 kB view details)

Uploaded CPython 3.12Windows x86-64

bosa_core_binary-0.8.0-cp312-cp312-manylinux_2_31_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.31+ x86-64

bosa_core_binary-0.8.0-cp312-cp312-macosx_13_0_x86_64.whl (827.2 kB view details)

Uploaded CPython 3.12macOS 13.0+ x86-64

bosa_core_binary-0.8.0-cp312-cp312-macosx_13_0_arm64.macosx_15_0_arm64.whl (692.2 kB view details)

Uploaded CPython 3.12macOS 13.0+ ARM64macOS 15.0+ ARM64

bosa_core_binary-0.8.0-cp311-cp311-win_amd64.whl (694.3 kB view details)

Uploaded CPython 3.11Windows x86-64

bosa_core_binary-0.8.0-cp311-cp311-manylinux_2_31_x86_64.whl (929.3 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.31+ x86-64

bosa_core_binary-0.8.0-cp311-cp311-macosx_13_0_x86_64.whl (808.5 kB view details)

Uploaded CPython 3.11macOS 13.0+ x86-64

bosa_core_binary-0.8.0-cp311-cp311-macosx_13_0_arm64.macosx_15_0_arm64.whl (674.6 kB view details)

Uploaded CPython 3.11macOS 13.0+ ARM64macOS 15.0+ ARM64

File details

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

File metadata

File hashes

Hashes for bosa_core_binary-0.8.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 f518a45e5093d4bedfe0e09010a9c717bb7bebe7148dec9cc7f1e1cbf35f3f8b
MD5 ca85783975421aed06bd89a3b17661c1
BLAKE2b-256 66bf9cb543436a551d2fc629a105d11894b328da7c56c6b7840793cb4b13c83b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for bosa_core_binary-0.8.0-cp313-cp313-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 830e06e002da5b6a113e2b68d5b860d0852dbc3f0c807fe2df34bb74bdb849c6
MD5 530bf429b43418d7a7316f273531f30a
BLAKE2b-256 39d072ad8fc63d07b988b06f163eacf517a332cc7d6d029fa39a1827aa43f21e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bosa_core_binary-0.8.0-cp313-cp313-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 f307c71f95a7d599d4f10de04d6bf2b4ccef69637a7f6635bc02f4361eb89afe
MD5 651ae7b121423724978b783714ad0ee1
BLAKE2b-256 291d142becb2f24c859625cce6b2d68fa54932b7aa820f6b1a45ad7118b89c1c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for bosa_core_binary-0.8.0-cp313-cp313-macosx_13_0_arm64.macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 ee47c4ee75fb2b2db26a3577bc1f8f2af8bab13dff71905c1cd0e9aa9c2761b3
MD5 646878870ff267eb1a52ce45b83c8fd1
BLAKE2b-256 113c5fee328b1e1e17b4a6602a67fd86fc9e46d344b7fa68140b58194864c112

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_core_binary-0.8.0-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.8.0-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.8.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 926f0578fce38d0c6e850e3dfd41b5f7e5a075087c457395bec3feef695ab340
MD5 8ec3f367bb384a637f77c5ab3e4ae889
BLAKE2b-256 0fdac72ac57f48f78e3a46d13e1150783ab49ef35696ffb6feb8825089ea875b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for bosa_core_binary-0.8.0-cp312-cp312-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 95352e94bb2d3398ff47038ba25bbcac211c63341b0101cf1bd1088f38b9b2f7
MD5 17e9905f634bc550dc7d93522553f5fd
BLAKE2b-256 c7c203ec4fdb07ca728ed57165eb30424cd5b8a5c1724389a0ff4d2d1d994a46

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bosa_core_binary-0.8.0-cp312-cp312-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 9d3dca6fbcd5d8a17a93804c5d85b3d417c4249d3b42c2178be72f702d9832b5
MD5 89cc7b6b6154f234adb21dc7c7ac9d31
BLAKE2b-256 d3f048f55e54705632e2f3a58e71ec7a187511727bf101751d746ceedc9d88c9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for bosa_core_binary-0.8.0-cp312-cp312-macosx_13_0_arm64.macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 dc3582b608888e4c65395f5e7358d49a60b97a3b3bbd646aefe4520a9bbca476
MD5 12ed64fc74048992f3f010b6ee056d78
BLAKE2b-256 12e6b0199142738299fbd43e6d18dd9c830bac8891562d061dff400b20b6e293

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_core_binary-0.8.0-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.8.0-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.8.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 6b9c3bbac35e9509e79e4b68dc558425ac42da619868320cc6523a7c756100d6
MD5 08013e3dc5352cd4417463e62a3e91a3
BLAKE2b-256 3d62677706f07023777f3ab55a0ccfe9cf1a1d0dbbcf5e835412f4a16c8f66ad

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for bosa_core_binary-0.8.0-cp311-cp311-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 d8711e537bf751c2992cb347128e8d66f7f1e12a6f7abaf463a4758063171881
MD5 41f97f01d020f216beaa012d5ec407f2
BLAKE2b-256 eaf124bd67d76b78d6bcfb33ee18d4b5bde82ef818e26ed9e12f7771e3ab1597

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bosa_core_binary-0.8.0-cp311-cp311-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 e619487f845d05888d838dbc0a8cdd825c80d11aec9c2370c7ff9671a2ffc2a2
MD5 8de1293799abfd079821b48e61bf7d91
BLAKE2b-256 c76945eab77036b872de22ea409ad5dc774848c4d48439f19ea2594f62be3db2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for bosa_core_binary-0.8.0-cp311-cp311-macosx_13_0_arm64.macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 7be395b4d35e63d40e75b0b2063eec37a51716193e15dacee718a0a779a56d34
MD5 58c9ae10f323b4fede714201b2d571f2
BLAKE2b-256 79a82ffeba1d64cd20e2074516271acfdcd24bff52e35e3edb788d01eddd3c30

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_core_binary-0.8.0-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