Skip to main content

No project description provided

Project description

DIFF TRACER

A FastAPI utility designed to compare two API responses, making it easier to validate behavior and ensure accuracy during refactoring.



Preview

[!WARNING] Please keep in mind that Diff Tracer is still under active development


Installation

 pip install diff_tracer

Basic Usage

To compare two results:

from diff_tracer import compare_async

@app.get("/")
async def get_data():
    return await compare_async(
        current_fn=lambda: currentUseCase(), # current function in production
        new_fn=lambda: newUseCase(), # new refactored function
        percentage=80, # percentage of requests to compare, good to control expensive endpoints
    )

Active the dashboard endpoint in your main file:

from fastapi import FastAPI
from diff_tracer import init_web_view


app = FastAPI()


init_web_view(app=app, security_token="362a9b3f302542deb3184671bbc3e7da")

Access http://localhost:{PORT}/diff-tracer-view/362a9b3f302542deb3184671bbc3e7da to view the dashboard.

Check a full working example on ./diff_tracer/fastapi_example.py

Why

I used this aproach while working on a major endpoint refactor at my current company. The endpoint was critical but lacked comprehensive tests, making it challenging to ensure the refactored function behaved identically to the original. While I wrote some tests, I wanted an extra layer of confidence before deploying to production.

Known issues

  • The dashboard endpoint is not secure. You can set a token to make it harder to access, but it's still not secure.
  • The files are saved local on your API, so everytime you make a new deploy they will be erased.

Contributing

For local development just install the libraries and start the FastAPI example file:

 poetry install
❯ poetry run task start_api

Access http://localhost:8000/users to simulate requests.

Access http://localhost:8000/diff-tracer-view/1234 to view de dashboard. 1234 is the default token.

To run the tests:

 poetry run task test

Thanks to

The code that makes the comparison is from Google Diff, Match and Patch Library written by Neil Fraser Copyright (c) 2006 Google Inc. http://code.google.com/p/google-diff-match-patch/

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

diff_tracer-0.0.1.tar.gz (26.3 kB view details)

Uploaded Source

Built Distribution

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

diff_tracer-0.0.1-py3-none-any.whl (27.7 kB view details)

Uploaded Python 3

File details

Details for the file diff_tracer-0.0.1.tar.gz.

File metadata

  • Download URL: diff_tracer-0.0.1.tar.gz
  • Upload date:
  • Size: 26.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.2 Linux/6.8.0-40-generic

File hashes

Hashes for diff_tracer-0.0.1.tar.gz
Algorithm Hash digest
SHA256 e258a19ebe520d1a27eae78e13e2b177b59110b8e4b44331b0e4a7d10515e8a5
MD5 de90e639938abb3e8054d519c084435c
BLAKE2b-256 5ddcefae28b385aed37843214f7ea50125d68756dec5d4ca4ce718c00cf95894

See more details on using hashes here.

File details

Details for the file diff_tracer-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: diff_tracer-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 27.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.2 Linux/6.8.0-40-generic

File hashes

Hashes for diff_tracer-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 396232f8444ae68a0366c57888a7292cf6dfe52623af7640ce8d7b559df6d9bb
MD5 fd05b81b92b914d1ca68dce2be33561f
BLAKE2b-256 19c3b5e4c80a1a86fa8b69593b5d310cd2ca03f15c06011f2dc953f4829f1f1d

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