AppChecker
AppChecker is an asynchronous tool for performing application health checks during startup. It can be particularly useful in applications like FastAPI, where it helps confirm that your dependencies are running and operational, including database access, RabbitMQ connectivity, and that your application is ready to respond to HTTP requests.
With AppChecker, you can easily register health check functions and manage their execution, making it a great fit for microservices and other applications that require health checks.
Installation
You can install AppChecker using pip:
pip install appchecker
using uv:
uv add appchecker
Example Usage
Each custom health check function, such as check_cache, should return either True for a successful check or False for a failed check. Here’s an example of how to use AppChecker for checking your application:
import asyncio
from appchecker import AppChecker # Import the AppChecker
# Create an instance of AppChecker
app_checker = AppChecker()
@app_checker.check_health
async def check_cache():
await asyncio.sleep(2) # Simulate the time taken to perform the check
return True # Successful check
async def main():
await app_checker.run_checks() # Run all checks
if __name__ == "__main__":
asyncio.run(main()) # Start the asyncio event loop
Alternative Usage
In addition to using the decorator for registering health checks, you can also register checks using the register_check method directly. Here's how you can do it:
app_checker = AppChecker()
async def check_cache():
await asyncio.sleep(2)
return True
# Register the health check function
app_checker.register_check(check_cache)
await app_checker.run_checks() # Run all checks
Example Output
When you run your checks, you’ll see output similar to this in the console:
---------------------------------------------------------------------------
check starts
---------------------------------------------------------------------------
collected 1 items
Starting check_cache...
✔ [SUCCESS] check_cache
---------------------------------------------------------------------------
1 [success] in 2.01s
---------------------------------------------------------------------------
All checks success.
Silent Mode
You can run the AppChecker in silent mode, which suppresses all console output. This can be useful if you want to only obtain results from the checks without any other output.
Enabling Silent Mode
To enable silent mode, simply pass silent_mode=True when creating an instance of AppChecker:
import asyncio
from appchecker import AppChecker
# Create an instance of AppChecker with silent mode enabled
app_checker = AppChecker(silent_mode=True)
@app_checker.check_health
async def check_cache():
await asyncio.sleep(2) # Simulate the time taken to perform the check
return True # Successful check (return False for a failed check)
async def main():
await app_checker.run_checks() # Run all checks
results = app_checker.get_results() # Get the results
for result in results:
print(f"{result.name}: {'Success' if result.success else 'Failure'}")
if __name__ == "__main__":
asyncio.run(main()) # Start the asyncio event loop
In this example, all console output during the checks will be suppressed, and you can use the get_results() method to view the results without any extra information cluttering your console.
How It Works
AppChecker allows you to register health check functions using the check_health decorator. Each health check function should be asynchronous and return a result (e.g., True for a successful check or raise an exception for a failed check).
When you call app_checker.run_checks(), all registered functions are invoked in sequence, and the results are displayed on the screen.
Features
- Asynchronous: Uses asynchronous functions for checks, which do not block the main execution flow.
- Flexibility: Easily add new checks by wrapping them in the decorator.
- Result Display: Conveniently displays the results of checks, including successful and failed checks.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contribution
If you have suggestions for improving AppChecker, feel free to create a Pull Request or open Issues in the repository.
Metadata
Release files for AppChecker 0.2.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| appchecker-0.2.3.tar.gz | 5.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| appchecker-0.2.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.8 kB
Release files / appchecker-0.2.3.tar.gz
| Download URL | appchecker-0.2.3.tar.gz |
|---|---|
| Size | 5.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8535229babf22ac0027b70f438ce8c9c11dc801bbe0a72d8ae59b2ed2d718b10
|
|
BLAKE2b-256 checksum How to use checksums |
b451b02c8e23224a6773dc666f2ce94e796a8e37b3a9c5ea0a28917184417532
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.10
|
Release files / appchecker-0.2.3-py3-none-any.whl
| Download URL | appchecker-0.2.3-py3-none-any.whl |
|---|---|
| Size | 5.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5ea526945a67a29e4396ab32dc22ac14035fa424619031216f67d34b55fc8b29
|
|
BLAKE2b-256 checksum How to use checksums |
3f8b46e49cbdacf1d188e68e379505bab2e3522c00d0e4cca15230f5e5796879
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.10
|
Security for AppChecker 0.2.3
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.