Skip to main content

About

pylint-restricted-imports is Pylint plugin for restricting what imports are allowed in specific module trees. Want to prevent django from being imported in a flask app? This plugin is for you!

Usage

Ensure pylint-restricted-imports is installed and on your path, and then run pylint using pylint-restricted-imports as a plugin:

pip install pylint-restricted-imports
pylint --load-plugins pylint_restricted_imports [..your module..]

Configuration

Before the plugin will do anything, it needs configuring. You can use pylint to generate the default configuration:

pylint --load-plugins pylint_restricted_imports --generate-rcfile

You will end up with a block similar to below:

[RESTRICTED-IMPORT]
# Colon/semicolon-delimited sets of names that determine what modules are
# allowed to be imported from another module
restricted-imports=

# Check restricted imports recursively
restricted-import-recurse=no

Restricted Imports

restricted-imports is a csv list of module/restricted imports. The format is <module>:<restricted module>;.... For example, the following would prevent restricted1 and restricted2 from being imported in module1 and restricted3 and restricted4 from being imported in module2:

module1:restricted1;restricted2,module2:fordibben3;restricted4

Recursion

You can enable the transitive detection of restricted imports, however this takes a lot more compute.

For example, if have the following files:

# flask_app.py
import flask
import common_utils

# common_utils.py
import django

If flask_app is not allowed to import django, the transitive checker would throw an error because importing common_utils would cause django to be imported, which is restricted.

Release files for pylint-restricted-imports 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pylint-restricted-imports 0.2.2
File Size Uploaded
pylint_restricted_imports-0.2.2.tar.gz 4.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pylint-restricted-imports 0.2.2
File Interpreter ABI Platform
pylint_restricted_imports-0.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 9.1 kB

Release files / pylint_restricted_imports-0.2.2.tar.gz

Download URL pylint_restricted_imports-0.2.2.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
7eef7309b4391091e2ceca81bc0cca5b6063bc2b381d6b39f8eb2118795c3d15
BLAKE2b-256 checksum
How to use checksums
079385c75d7da4b100fb420ff4bd5afd48c2ab116870fd91f7a802e21b32e1b4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.9.1 Darwin/23.5.0

Release files / pylint_restricted_imports-0.2.2-py3-none-any.whl

Download URL pylint_restricted_imports-0.2.2-py3-none-any.whl
Size 4.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1a0dfdb9a9a2370d8b22263be83c974d9fcebe9abdf7dd29f020f4c26bb476d9
BLAKE2b-256 checksum
How to use checksums
6134296c746d3617d5f506873c9d2558052a872133aaa4add4d8cabdfdcb29ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.9.1 Darwin/23.5.0

Release history Release notifications | RSS feed

This release

0.2.2 This release

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page