You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+48-35Lines changed: 48 additions & 35 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,19 +11,21 @@
11
11
12
12
-[Overview](#overview)
13
13
-[Quickstart](#quickstart)
14
-
-[Installation](#installation)
15
-
-[Docker](#docker)
16
-
-[Run](#run)
17
-
-[JSON Format](#json-format)
14
+
-[Using `Twyn` as a cli tool](#using-twyn-as-a-cli-tool)
15
+
-[Installation](#installation)
16
+
-[Docker](#docker)
17
+
-[Run](#run)
18
+
-[JSON Format](#json-format)
19
+
-[Using `Twyn` as a library](#using-twyn-as-a-library)
20
+
-[Logging level](#logging-level)
18
21
-[Configuration](#configuration)
19
22
-[Allowlist](#allowlist)
20
23
-[Dependency files](#dependency-files)
21
24
-[Check dependencies introduced through the CLI](#check-dependencies-introduced-through-the-cli)
22
25
-[Selector method](#selector-method)
23
26
-[Configuration file](#configuration-file)
24
27
-[Cache](#cache)
25
-
-[Using `Twyn` as a library](#using-twyn-as-a-library)
26
-
-[Logging level](#logging-level)
28
+
27
29
28
30
## Overview
29
31
`Twyn` is a security tool that compares the name of your dependencies against a set of the most popular ones,
@@ -32,22 +34,23 @@ In short, `Twyn` protects you against [typosquatting attacks](https://en.wikiped
32
34
33
35
It works as follows:
34
36
35
-
1. Either choose to scan the dependencies in a dependencies file you specify (`--dependency-file`) or some dependencies introduced through the CLI (`--dependency`). If no option was provided, it will try to find a dependencies file in your working path.
37
+
1. Either choose to scan the dependencies in a dependencies file you specify (`--dependency-file`) or some dependencies introduced through the CLI (`--dependency`). If no option was provided, it will try to find a dependencies file in your working path. It will try to parse all the supported dependency files that it finds. To know which files are supported head to the [Dependency files](#dependency-files) section.
36
38
2. If the name of your package name matches with the name of one of the most well known packages, the package is accepted.
37
39
3. If the name of your package is similar to the name of one of the most used packages, `Twyn` will prompt an error.
38
40
4. If your package name is not in the list of the most known ones and is not similar enough to any of those to be considered misspelled, the package is accepted. `Twyn` assumes that you're using either a not so popular package (therefore it can't verify its legitimacy) or a package created by yourself, therefore unknown for the rest.
39
41
40
42
## Quickstart
41
43
42
-
### Installation
44
+
### Using twyn as a CLI tool
45
+
#### Installation
43
46
44
47
`Twyn` is available on PyPi repository, you can install it by running
45
48
46
49
```sh
47
-
pip install twyn
50
+
pip install twyn[cli]
48
51
```
49
52
50
-
### Docker
53
+
####Docker
51
54
52
55
`Twyn` provides a Docker image, which can be found [here](https://hub.docker.com/r/elementsinteractive/twyn).
`Twyn` also supports being used as 3rd party library for you project. To install it, run:
95
+
96
+
97
+
```sh
98
+
pip install twyn
99
+
```
100
+
101
+
Example usage in your code:
102
+
103
+
```python
104
+
from twyn import check_dependencies
105
+
106
+
typos = check_dependencies()
107
+
108
+
for typo in typos.errors:
109
+
print(f"Dependency:{typo.dependency}")
110
+
print(f"Did you mean any of [{','.join(typo.similars)}]")
111
+
112
+
```
113
+
114
+
#### Logging level
115
+
By default, logging is disabled when running as a 3rd party library. To override this behaviour, you can:
116
+
117
+
```python
118
+
logging.basicConfig(level=logging.INFO)
119
+
logging.getLogger("twyn").setLevel(logging.INFO)
120
+
```
121
+
87
122
## Configuration
88
123
89
124
### Allowlist
90
125
91
-
It can happen that a legitimate package known by the user raises an error because is too similar to one of the most trusted ones.
92
-
You can then add this packages to the `allowlist`, so it will be skipped:
126
+
It can happen that a legitimate package known by the user raises an error because it is too similar to one of the most trusted ones. Imagine that you are using internally a package that you developed called `reqests`. You can then add this packages to the `allowlist`, so it will not be reported as a typo:
93
127
94
128
```sh
95
129
twyn allowlist add <package>
@@ -201,24 +235,3 @@ To clear the cache, run:
201
235
```
202
236
203
237
204
-
### Using Twyn as a library
205
-
206
-
`Twyn` also supports being used as 3rd party library for you project.
207
-
208
-
```python
209
-
from twyn import check_dependencies
210
-
211
-
typos = check_dependencies()
212
-
213
-
for typo in typos.errors:
214
-
print(f"Dependency:{typo.dependency}")
215
-
print(f"Did you mean any of [{','.join(typo.similars)}]")
216
-
217
-
```
218
-
### Logging level
219
-
To override the logging level when using `Twyn` as a 3rd party library, simply override it like:
0 commit comments