Skip to content

Commit e7aaa07

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

1 file changed

Lines changed: 39 additions & 10 deletions

File tree

README.md

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,47 +6,48 @@
66
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
77
[![License](https://img.shields.io/github/license/elementsinteractive/twyn)](LICENSE)
88

9-
![](https://github.com/elementsinteractive/twyn/blob/main/assets/twyn.gif)
10-
119
## Table of Contents
1210

1311
- [Overview](#overview)
1412
- [Quickstart](#quickstart)
1513
- [Installation](#installation)
1614
- [Docker](#docker)
1715
- [Run](#run)
16+
- [JSON Format](#json-format)
1817
- [Configuration](#configuration)
1918
- [Allowlist](#allowlist)
2019
- [Dependency files](#dependency-files)
2120
- [Check dependencies introduced through the CLI](#check-dependencies-introduced-through-the-cli)
2221
- [Selector method](#selector-method)
2322
- [Configuration file](#configuration-file)
23+
- [Cache] (#cache)
24+
- [Using `Twyn` as a library] (#using-twyn-as-a-library)
2425

2526
## Overview
26-
Twyn is a security tool that compares the name of your dependencies against a set of the most popular ones,
27+
`Twyn` is a security tool that compares the name of your dependencies against a set of the most popular ones,
2728
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).
29+
In short, `Twyn` protects you against [typosquatting attacks](https://en.wikipedia.org/wiki/Typosquatting).
2930

3031
It works as follows:
3132

3233
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.
3334
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.
35+
3. If the name of your package is similar to the name of one of the most used packages, `Twyn` will prompt an error.
36+
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.
3637

3738
## Quickstart
3839

3940
### Installation
4041

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

4344
```sh
4445
pip install twyn
4546
```
4647

4748
### Docker
4849

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

5152
Use it like so:
5253

@@ -69,6 +70,18 @@ For a list of all the available options as well as their expected arguments run:
6970
twyn run --help
7071
```
7172

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

7487
### Allowlist
@@ -135,7 +148,7 @@ twyn run --selector-method <method>
135148

136149
### Configuration file
137150

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.
151+
You can save your configurations in a `.toml` file, so you don't need to specify them everytime you run `Twyn` in your terminal.
139152

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

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

176189
You can disable the cache by adding the following flag:
177190

@@ -185,4 +198,20 @@ Cache file is valid for 30 days, after that period it will download again the tr
185198
To clear the cache, run:
186199
```python
187200
twyn run cache clear
201+
```
202+
203+
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("all")
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+
188217
```

0 commit comments

Comments
 (0)