Skip to content

Commit fee992d

Browse files
committed
docs: update docs with json and "twyn as a package" examples
1 parent 8b09af6 commit fee992d

1 file changed

Lines changed: 39 additions & 11 deletions

File tree

README.md

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,48 +5,48 @@
55
[![Python Version](https://img.shields.io/badge/python-3.9%20%7C%203.10%20%7C%203.11%20%7C%203.12%20%7C%203.13-blue?logo=python&logoColor=yellow)](https://pypi.org/project/twyn/)
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)
8-
9-
![](https://github.com/elementsinteractive/twyn/blob/main/assets/twyn.gif)
10-
118
## Table of Contents
129

1310
- [Overview](#overview)
1411
- [Quickstart](#quickstart)
1512
- [Installation](#installation)
1613
- [Docker](#docker)
1714
- [Run](#run)
15+
- [JSON Format](#json-format)
1816
- [Configuration](#configuration)
1917
- [Allowlist](#allowlist)
2018
- [Dependency files](#dependency-files)
2119
- [Check dependencies introduced through the CLI](#check-dependencies-introduced-through-the-cli)
2220
- [Selector method](#selector-method)
2321
- [Configuration file](#configuration-file)
22+
- [Cache] (#cache)
23+
- [Using `Twyn` as a library] (#using-twyn-as-a-library)
2424

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

3030
It works as follows:
3131

3232
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.
3333
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.
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.
3636

3737
## Quickstart
3838

3939
### Installation
4040

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

4343
```sh
4444
pip install twyn
4545
```
4646

4747
### Docker
4848

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

5151
Use it like so:
5252

@@ -69,6 +69,18 @@ For a list of all the available options as well as their expected arguments run:
6969
twyn run --help
7070
```
7171

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

7486
### Allowlist
@@ -135,7 +147,7 @@ twyn run --selector-method <method>
135147

136148
### Configuration file
137149

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

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

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

176188
You can disable the cache by adding the following flag:
177189

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

0 commit comments

Comments
 (0)