Skip to main content

core-apis

This project/library contains useful elements related to APIs and provides basic structures to speed up the implementation of an API service using the FastApi framework as base…


PyPI Downloads Python Versions License Pipeline Status Docs Status Security

Installation

Install from PyPI using pip:

pip install core-apis
uv pip install core-apis  # Or using UV...

Features

FastAPI Server Management

  • Quick server setup with uvicorn ASGI server

  • Environment-based configuration (HOST, PORT, DEBUG, LOG_LEVEL)

  • Secure defaults (localhost-only binding)

Application Factory

  • AppConfig dataclass consolidating all application parameters (name, version, description, base_path, cors_config, debug)

  • CorsConfig dataclass for CORS middleware (origins, methods, headers)

  • create_application(app_config: AppConfig) factory with safe defaults

Router Management

  • Plugin architecture: register routers at import time via add_router()

  • Runtime addition: attach routers to an existing app via app.include_router()

  • reset_routers() for clearing the registry between tests

  • Built-in health check endpoint (/api/ping)

Response Standardization

  • @wrap_response decorator for consistent API responses

  • ApiResponse TypedDict contract: code, status, result, error

  • HTTP status code mapping (2XX success, 4XX error, 5XX failure)

  • Automatic exception handling for ServiceException and InternalServerError

Testing Utilities

  • BaseApiTestCases class for FastAPI testing with pre-configured TestClient

  • setUp() calls reset_routers() automatically to prevent cross-test pollution

  • init_client(with_cors=True) for flexible test application initialization

How to use it

The simple way to spin up the FastAPI server locally using uvicorn:

# -*- coding: utf-8 -*-
from core_apis.api import server
server.run()

Creating an application with custom configuration (AppConfig / CorsConfig):

# -*- coding: utf-8 -*-
from core_apis.api import create_application, AppConfig, CorsConfig

app = create_application(
    app_config=AppConfig(
        name="My Service",
        version="1.0.0",
        cors_config=CorsConfig(
            enabled=True,
            origins=["https://example.com"],
        ),
    ),
)

Adding custom routers — plugin architecture (recommended):

Use add_router() to register routers at import time. They are collected by create_application() when the app is built. This is the recommended pattern for plugins and reusable components that don’t need a reference to the app instance.

# -*- coding: utf-8 -*-

from fastapi import APIRouter

from core_apis.api import server
from core_apis.api.routers import add_router

router = APIRouter()
add_router(router)

@router.get(path="/server_status")
def get_server_status():
    return {"status": "OK"}

server.run()

Adding routers at runtime (post-creation):

Use app.include_router() directly on the FastAPI instance after the application has already been created. Useful for dynamic or conditional route registration.

# -*- coding: utf-8 -*-

from fastapi import APIRouter

from core_apis.api import create_application

app = create_application()

late_router = APIRouter()

@late_router.get(path="/status")
def get_status():
    return {"status": "OK"}

app.include_router(late_router, prefix="/api")

Using @wrap_response — standardized response contract (ApiResponse):

# -*- coding: utf-8 -*-

from core_https import HTTPStatus
from core_apis.decorators import wrap_response

@wrap_response
def get_item(item_id: int):
    return HTTPStatus.OK, {"id": item_id, "name": "Widget"}

# Returns an ApiResponse dict:
# {"code": 200, "status": "success", "result": {"id": 1, "name": "Widget"}, "error": None}

For an example of the structure of a production-ready project check: https://gitlab.com/bytecode-solutions/examples/fastapi-project

Quick Start

Installation

Install the package:

pip install core-apis
uv pip install core-apis  # Or using UV...
pip install -e ".[dev]"    # For development...

Setting Up Environment

  1. Install required libraries:

pip install --upgrade pip
pip install virtualenv
  1. Create Python virtual environment:

virtualenv --python=python3.12 .venv
  1. Activate the virtual environment:

source .venv/bin/activate

Install packages

pip install .
pip install -e ".[dev]"

Check tests and coverage

python manager.py run-tests
python manager.py run-coverage

Contributing

Contributions are welcome! Please:

  1. Fork the repository

  2. Create a feature branch

  3. Write tests for new functionality

  4. Ensure all tests pass: pytest -n auto

  5. Run linting: pylint core_apis

  6. Run security checks: bandit -r core_apis

  7. Submit a pull request

License

This project is licensed under the MIT License. See the LICENSE file for details.

Support

For questions or support, please open an issue on GitLab or contact the maintainers.

Authors

Metadata

Release files for core-apis 2.1.2

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

Source distribution (sdist)

Source distribution for core-apis 2.1.2
File Size Uploaded Provenance Actions
core_apis-2.1.2.tar.gz 13.1 kB With provenance Details for core_apis-2.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for core-apis 2.1.2
File Interpreter ABI Platform Actions
core_apis-2.1.2-py3-none-any.whl Python 3 none any Details for core_apis-2.1.2-py3-none-any.whl

Total release size: 26.3 kB

Release files / core_apis-2.1.2.tar.gz

Download URL core_apis-2.1.2.tar.gz
Size 13.1 kB
Tags Source
SHA-256 checksum
How to use checksums
01729df1e3a0e16d2156c506f22a745ce575d51e9e56e120f8253e2ca68d16c2
BLAKE2b-256 checksum
How to use checksums
50a861931ab41a751f69c5fae9c7d36246127826c07d5c74bb8f11aad5a481e4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.15.2

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitLab CI/CD, verified by PyPI on Nov 16, 2026.

Transparency log

Release files / core_apis-2.1.2-py3-none-any.whl

Download URL core_apis-2.1.2-py3-none-any.whl
Size 13.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
31a9adc53f3b7740acbc7e60bcffd513dd2eaa01f17b8cb63f33189ae9e4e223
BLAKE2b-256 checksum
How to use checksums
f0e52e6132362f621f0a0fee533d3b94ccf047fc3d0ddfaa0474b0db73527714
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.15.2

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitLab CI/CD, verified by PyPI on Nov 16, 2026.

Transparency log

Security for core-apis 2.1.2

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for core_apis-2.1.2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitLab CI/CD, verified by PyPI on Nov 16, 2026.

Transparency log

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.

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