Skip to main content

This project/library contains useful elements related to APIs...

Project description

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…


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

  • Create pre-configured FastAPI applications

  • Customizable name, version, description, and base path

  • Built-in CORS middleware support

  • Debug mode configuration

Router Management

  • Dynamic router registration system

  • Add custom routers before application creation

  • Automatic router inclusion with configurable base path

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

Response Standardization

  • @wrap_response decorator for consistent API responses

  • Standardized response format with code, status, and result/error fields

  • Automatic exception handling for ServiceException and InternalServerError

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

Testing Utilities

  • BaseApiTestCases class for FastAPI testing

  • Pre-configured TestClient setup

  • Automatic test application initialization

  • CORS configuration for test environments

How to use it

The simple way to spin up the FastAPI server and running it locally using uvicorn

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

Adding custom routers…

# -*- 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 new_router():
    return {"status": "OK"}

server.run()

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

core_apis-1.0.1.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

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

core_apis-1.0.1-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file core_apis-1.0.1.tar.gz.

File metadata

  • Download URL: core_apis-1.0.1.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for core_apis-1.0.1.tar.gz
Algorithm Hash digest
SHA256 598ae910032fcb01fb1e6dd710a5eef6d4a07b9933e98dbd52d8797f37714505
MD5 b83d9db0188cf280a557012396f42d4c
BLAKE2b-256 bde4a08c0482b45d167f9777552428306f802f80c4fe667e95b3d7351ceb8103

See more details on using hashes here.

File details

Details for the file core_apis-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: core_apis-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 10.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for core_apis-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 591de47747c2f6022a43e36925c4b3e0efdf78ea44d007969deccad87131c7c6
MD5 2084f717cff0d24330e00583acd7ec12
BLAKE2b-256 ce9c0cef9bbb1c7c0a7156ddda856446e6e6c9bffd3a7070bb2cff674f1fad2a

See more details on using hashes here.

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