A Python tool to guard against incorrect usage of python modules.
Project description
modguard
A Python tool to guard against incorrect usage of python modules.
What is modguard?
Modguard enables you to explicitly define the public interface for a given module.
This helps prevent other developers unintentionally mis-using code, which can lead to poor performance, security vulnerabilities, bugs, and more.
By declaring a module within modguard, all members of the module will be made private by default. Each member of the interface that you intend to make public can then be exposed through a simple decorator.
Modguard is incredibly lightweight, and has no impact on the runtime of your code. Instead, it's checks are performed through a lightweight CLI tool.
Installation
pip install modguard
Usage
Add a Boundary
to the __init__.py
of the module you're creating an interface for.
# core/__init__.py
from modguard import Boundary
Boundary(__name__)
Implement the public
decorator on any part of the interface that is public
# core/main.py
from modguard import public
# Adding the decorator here signifies this function is public
@public
def public_function(user_id: int) -> str:
...
# This function will now be considered private
def private_function():
...
Modguard will now flag any incorrect usages of your interface.
> # From the root of your project
> guard .
1 error found.
utils/helpers.py:L45-60 E001 Restricted usage of 'core.main.private_function' in 'utils.helpers'
Details
Modguard works by analyzing the abstract syntax tree of your codebase. It will only protect against usages that are within the scope of the cli runtime, which is why we suggest always running the tool from the root of your project.
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file modguard-0.1.1.tar.gz
.
File metadata
- Download URL: modguard-0.1.1.tar.gz
- Upload date:
- Size: 18.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ff4fb926a7efc133f7450f6988bb8740dc36c8a5490d7e81b32d70b0d22d359 |
|
MD5 | 8594a93d2d8a843ea356f8ce1e959ba2 |
|
BLAKE2b-256 | a9b0c35dd9e23eaf46fbf31b3793cfb89be8f6545864592b6c430452279ddba3 |
File details
Details for the file modguard-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: modguard-0.1.1-py3-none-any.whl
- Upload date:
- Size: 18.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f5c7a5a12742deeae4da27760e84f065d9f024d71fa0570032f6a1aed381fe31 |
|
MD5 | a929d8626328b72ccd9527b6387f05bb |
|
BLAKE2b-256 | 019ab6ab52a0ca78cd4db2c6a26289d04af50e1a5dd0742940bc2d259bf7157a |