Core utilities and helpers for VP projects.
- Structured Logging: JSON-formatted logging with support for Pydantic models and context tracking.
- FastAPI Middleware: Out-of-the-box middleware for request/response logging, request ID generation, and performance tracking.
- Helpers: Common utility functions for case conversion, JSON parsing, and more.
You can install this package directly from GitHub:
pip install git+https://github.com/Volopay/vp-python-core.gitOr add it to your pyproject.toml:
dependencies = [
"vp-core @ git+https://github.com/Volopay/vp-python-core.git"
]from vp_core import setup_logging, get_logger
# Initialize logging at the start of your application
setup_logging()
logger = get_logger(__name__)
logger.info("Application started", extra={"version": "1.0.0"})from vp_core.helpers.case_converter import to_camel
camel_case = to_camel("snake_case_string")
# Output: "snakeCaseString"To use the logging middleware in a FastAPI application:
from fastapi import FastAPI
from vp_core.logging.middleware import logging_middleware
app = FastAPI()
app.middleware("http")(logging_middleware)To update to the latest version from the git repository, run:
pip install --upgrade git+https://github.com/Volopay/vp-python-core.gitIf you are using a requirements.txt or pyproject.toml file, pip install will usually respect the version unless you force an update or change the commit/branch.
If you are developing another project locally and want to use this package without publishing it, you can add it to your pyproject.toml using Poetry:
poetry add /path/to/vp-coreOr manually add it to your pyproject.toml in the other project:
[tool.poetry.dependencies]
vp-core = { path = "../vp-core", develop = true }Note: Setting develop = true ensures that any changes you make in the vp-core project are immediately reflected in your other project without needing to reinstall.
This package uses pytest for testing, pytest-cov for coverage, and pytest-benchmark for benchmarking.
First, install the test dependencies:
pip install -e ".[test]"To run tests:
pytestTo run benchmarks:
pytest --benchmark-only