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.2.tar.gz
.
File metadata
- Download URL: modguard-0.1.2.tar.gz
- Upload date:
- Size: 18.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c2d288e9b0fd4b77ccadac0c2a801818e368ded035a9c851789dfed837b6e81 |
|
MD5 | 9f584563df378886f9d98c89151b9322 |
|
BLAKE2b-256 | 8ed5d342540ff002d8dafbc8a4265352fd23be627b68ebe226796beafda6a0a0 |
File details
Details for the file modguard-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: modguard-0.1.2-py3-none-any.whl
- Upload date:
- Size: 18.8 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 | eab362e23b88fd781f2fc0d7af78ea34e399c3dfdba5361beaceca18336152a3 |
|
MD5 | e2b6472f73b05deec86bd8335f9fb9fe |
|
BLAKE2b-256 | e8b87411a10c186dffff6604527915e7d8a650c5d844d7a79fa299787b53ee7a |