Skip to main content

A tool to help you find and remove unused imports in your python project.

Project description

DEJANKIFY -- remove the jank from your code

This is a tool that helps you maintain your python environment by removing unnecessary dependencies. By default, it will remove all packages that are not explicitly imported in your code. It will also remove any import statements that are for packages that are not referenced in your code. It also creates a requirements.txt file that contains all the packages that are explicitly imported in your code and are not part of the standard library and are pip installable.

This is meant to enhance workflows that are using virtual environments and pip to manage dependencies.

Dejankify works best with pyenv, virtualenv, black, isort, and pylint.

Usage: dejankify [options]

To install run:

pip install dejankify

A sample script before dejankify:

import os
import sys
import re
import json
import requests
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

from sklearn import linear_model
from sklearn.metrics import mean_squared_error, r2_score

name = input("What is your name? ")
first, last = re.match(r"(\w+)\s(\w+)", name).groups()
print(f"Hello {first} {last}!")

The above script would imply the following external dependencies:

  • numpy
  • pandas
  • matplotlib
  • sklearn

Before running dejankify, you would need to install the above packages in your virtual environment and when your code runs it would import the above packages, which would be unnecessary if you are not using them and would slow down your code in addition to increasing the size of your virtual environment.

Now, let's run dejankify:

dejankify

After running dejankify, the script would look like this:

import re

name = input("What is your name? ")
first, last = re.match(r"(\w+)\s(\w+)", name).groups()
print(f"Hello {first} {last}!")

The above script would have no external dependencies and would run faster.

Dejankify will also create several files after it runs that you may delete or version control:

  • requirements.txt - contains all the packages that are explicitly imported in your code and are not part of the standard library and are pip installable.
  • temp_requirements.txt - Your original requirements.txt file will be renamed to this file.
  • invalid_requirements.json - contains a list of packages that are explicitly imported in your code but are not pip installable.
  • valid_requirements.json - contains a list of packages that are explicitly imported in your code and are pip installable.
  • builtins.json - contains a list of all the built-in modules in your version of python.

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

dejankify-0.1.1.tar.gz (16.8 kB view hashes)

Uploaded Source

Built Distribution

dejankify-0.1.1-py3-none-any.whl (17.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page