Skip to content

Commit 54d9708

Browse files
committed
docs: add json docs
1 parent 8b09af6 commit 54d9708

1 file changed

Lines changed: 39 additions & 8 deletions

File tree

README.md

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,38 +15,41 @@
1515
- [Installation](#installation)
1616
- [Docker](#docker)
1717
- [Run](#run)
18+
- [JSON Format](#json-format)
1819
- [Configuration](#configuration)
1920
- [Allowlist](#allowlist)
2021
- [Dependency files](#dependency-files)
2122
- [Check dependencies introduced through the CLI](#check-dependencies-introduced-through-the-cli)
2223
- [Selector method](#selector-method)
2324
- [Configuration file](#configuration-file)
25+
- [Cache] (#cache)
26+
- [Using `Twyn` as a library] (#using-twyn-as-a-library)
2427

2528
## Overview
26-
Twyn is a security tool that compares the name of your dependencies against a set of the most popular ones,
29+
`Twyn` is a security tool that compares the name of your dependencies against a set of the most popular ones,
2730
in order to determine if there is any similarity between them, preventing you from using a potentially illegitimate one.
28-
In short, Twyn protects you against [typosquatting attacks](https://en.wikipedia.org/wiki/Typosquatting).
31+
In short, `Twyn` protects you against [typosquatting attacks](https://en.wikipedia.org/wiki/Typosquatting).
2932

3033
It works as follows:
3134

3235
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.
3336
2. If the name of your package name matches with the name of one of the most well known packages, the package is accepted.
34-
3. If the name of your package is similar to the name of one of the most used packages, Twyn will prompt an error.
35-
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.
37+
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+
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.
3639

3740
## Quickstart
3841

3942
### Installation
4043

41-
Twyn is available on PyPi repository, you can install it by running
44+
`Twyn` is available on PyPi repository, you can install it by running
4245

4346
```sh
4447
pip install twyn
4548
```
4649

4750
### Docker
4851

49-
Twyn provides a Docker image, which can be found [here](https://hub.docker.com/r/elementsinteractive/twyn).
52+
`Twyn` provides a Docker image, which can be found [here](https://hub.docker.com/r/elementsinteractive/twyn).
5053

5154
Use it like so:
5255

@@ -69,6 +72,18 @@ For a list of all the available options as well as their expected arguments run:
6972
twyn run --help
7073
```
7174

75+
### JSON format
76+
If you want your output in JSON format, you can run `Twyn` with the following flag:
77+
78+
```python
79+
twyn run --json
80+
```
81+
This will output:
82+
83+
```json
84+
{"errors":[{"dependency":"reqests","similars":["requests","grequests"]}]}
85+
```
86+
7287
## Configuration
7388

7489
### Allowlist
@@ -135,7 +150,7 @@ twyn run --selector-method <method>
135150

136151
### Configuration file
137152

138-
You can save your configurations in a `.toml` file, so you don't need to specify them everytime you run Twyn in your terminal.
153+
You can save your configurations in a `.toml` file, so you don't need to specify them everytime you run `Twyn` in your terminal.
139154

140155
By default, it will try to find a `pyproject.toml` file in your working directory when it's trying to load your configurations.
141156
However, you can specify a config file as follows:
@@ -171,7 +186,7 @@ The file format for each reference is as follows:
171186
```
172187

173188
### Cache
174-
By default, Twyn will cache the list of trusted packages to a cache file (.twyn/trusted_packages.json).
189+
By default, `Twyn` will cache the list of trusted packages to a cache file (.twyn/trusted_packages.json).
175190

176191
You can disable the cache by adding the following flag:
177192

@@ -185,4 +200,20 @@ Cache file is valid for 30 days, after that period it will download again the tr
185200
To clear the cache, run:
186201
```python
187202
twyn run cache clear
203+
```
204+
205+
206+
### Using Twyn as a library
207+
208+
`Twyn` also supports being used as 3rd party library for you project.
209+
210+
```python
211+
from twyn import check_dependencies
212+
213+
typos = check_dependencies("all")
214+
215+
for typo in typos.errors:
216+
print(f"Dependency:{typo.dependency}")
217+
print(f"Did you mean any of [{','.join(typo.similars)}]")
218+
188219
```

0 commit comments

Comments
 (0)