Skip to content

Commit 5397352

Browse files
author
Dan Hertz
authored
Merge pull request #22 from nightfallai/add-documentation
add documentation
2 parents 7b03ca8 + 602c536 commit 5397352

File tree

6 files changed

+165
-29
lines changed

6 files changed

+165
-29
lines changed

CODEOWNERS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# These owners will be the default owners for everything in
2+
# the repo.
3+
* @evanfuller @austinphilp @smkent @dhertz

CONTRIBUTING.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Contributing
2+
3+
Thank you for considering contributing to the Nightfall Python SDK.
4+
5+
There are many ways to contribute, such as:
6+
* Writing code samples
7+
* Suggesting documentation improvements
8+
* Submitting bug reports and feature requests
9+
* Writing code to improve the library itself.
10+
11+
Please, don't use the issue tracker for personal support questions. Feel free to reach out to `[email protected]`
12+
to address those issues.
13+
14+
## Responsibilities
15+
* Ensure cross-platform compatibility for every change that's accepted. Windows, Mac, Debian & Ubuntu Linux, etc.
16+
* Ensure backwards compatibility with Python 3.7+.
17+
* Create issues for each major change and enhancement that you wish to make.
18+
* Discuss proposed changes transparently and collect community feedback.
19+
* Avoid introducing new external dependencies whenever possible. When absolutely required, validate the software
20+
licenses used by these dependencies (e.g. avoid unintentional copyleft requirements).
21+
22+
## How to report a bug
23+
24+
### Security Disclosures
25+
If you find a security vulnerability, do NOT open an issue. Email `[email protected]` instead.
26+
27+
In order to determine whether you are dealing with a security issue, ask yourself the following questions:
28+
* Can I access something that's not mine, or something I shouldn't have access to?
29+
* Can I disable something for other people?
30+
* Is there a potential vulnerability stemming from a library dependency?
31+
32+
If you answered yes to any of the above questions, then you're probably dealing with a security issue.
33+
Note that even if you answer "no" to all questions, you may still be dealing with a security issue, so if you're
34+
unsure, just email us at `[email protected]`.
35+
36+
### Creating an Issue
37+
When filing an issue, make sure to answer these questions:
38+
1. What version of Java are you using?
39+
2. What operating system and processor architecture are you using?
40+
3. How did you discover the issue?
41+
4. Is the issue reproducible? What are the steps to reproduce?
42+
5. What did you expect to see?
43+
6. What did you see instead?
44+
45+
46+
## Suggesting a New Feature
47+
48+
If you find yourself wishing for a feature that doesn't exist in this SDK, you are probably not alone.
49+
There are bound to be others out there with similar needs. Open an issue on our issues list on GitHub which
50+
describes the feature you would like to see, why you need it, and how it should work.
51+
52+
## Code Review
53+
54+
The core team looks at open pull requests on a regular basis. In order for your pull request to be merged, it
55+
must meet the following requirements:
56+
* It must pass the checkstyle linter; this should be run automatically when you run `mvn package`.
57+
* It must add unit tests to cover any new functionality.
58+
* It must get approval from one of the code owners.
59+
60+
If a pull request remains idle for more than two weeks, we may close it.

README.md

Lines changed: 100 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,122 @@
11
# Nightfall Python SDK
22

3-
This is a python SDK for working with the Nightfall API.
3+
**Embed Nightfall scanning and detection functionality into Python applications**
44

55
[![PyPI version](https://badge.fury.io/py/nightfall.svg)](https://badge.fury.io/py/nightfall)
66

7+
## Features
78

8-
## Installation
9+
This SDK provides Python functions for interacting with the Nightfall API. It allows you to add functionality to your
10+
applications to scan plain text and files in order to detect different categories of information. You can leverage any
11+
of the detectors in Nightfall's pre-built library, or you may programmatically define your own custom detectors.
912

10-
This module requires Python 3.7 or higher.
13+
Additionally, this library provides convenience features such as encapsulating the steps to chunk and upload files.
14+
15+
To obtain an API Key, login to the [Nightfall dashboard](https://app.nightfall.ai/) and click the section
16+
titled "Manage API Keys".
17+
18+
See our [developer documentation](https://docs.nightfall.ai/docs/entities-and-terms-to-know) for more details about
19+
integrating with the Nightfall API.
20+
21+
## Dependencies
22+
23+
The Nightfall Python SDK requires Python 3.7 or later.
24+
25+
For a full list of external dependencies please consult `setup.py`.
26+
27+
28+
## Installation
1129

1230
```
1331
pip install nightfall
1432
```
1533

16-
## Quickstart
34+
## Usage
1735

18-
Make a new [API Token](https://app.nightfall.ai/api/) in Nightfall and store the value as an environment variable.
1936

20-
```python
21-
import os
37+
### Scanning Plain Text
2238

39+
Nightfall provides pre-built detector types, covering data types ranging from PII to PHI to credentials. The following
40+
snippet shows an example of how to scan using pre-built detectors.
41+
42+
#### Sample Code
43+
44+
```python
2345
from nightfall import Confidence, DetectionRule, Detector, Nightfall
2446

25-
nightfall = Nightfall(os.getenv('NIGHTFALL_API_KEY'))
47+
# By default, the client reads the API key from the environment variable NIGHTFALL_API_KEY
48+
nightfall = Nightfall()
49+
50+
# A rule contains a set of detectors to scan with
51+
detection_rule = DetectionRule([
52+
Detector(min_confidence=Confidence.LIKELY, nightfall_detector="CREDIT_CARD_NUMBER"),
53+
Detector(min_confidence=Confidence.POSSIBLE, nightfall_detector="US_SOCIAL_SECURITY_NUMBER"),
54+
])
2655

2756
findings, _ = nightfall.scan_text(
28-
["4916-6734-7572-5015 is my credit card number"],
29-
[DetectionRule(
30-
[Detector(min_confidence=Confidence.LIKELY,
31-
nightfall_detector="CREDIT_CARD_NUMBER")])])
57+
["hello world", "my SSN is 678-99-8212", "4242-4242-4242-4242"],
58+
[detection_rule]
59+
)
60+
3261
print(findings)
3362
```
63+
### Scanning Files
64+
65+
Scanning common file types like PDF's or office documents typically requires cumbersome text
66+
extraction methods like OCR.
67+
68+
Rather than implementing this functionality yourself, the Nightfall API allows you to upload the
69+
original files, and then we'll handle the heavy lifting.
70+
71+
The file upload process is implemented as a series of requests to upload the file in chunks. The library
72+
provides a single method that wraps the steps required to upload your file. Please refer to the
73+
[API Reference](https://docs.nightfall.ai/reference) for more details.
74+
75+
The file is uploaded synchronously, but as files can be arbitrarily large, the scan itself is conducted asynchronously.
76+
The results from the scan are delivered by webhook; for more information about setting up a webhook server, refer to
77+
[the docs](https://docs.nightfall.ai/docs/creating-a-webhook-server).
78+
79+
#### Sample Code
80+
81+
```python
82+
from nightfall import Confidence, DetectionRule, Detector, Nightfall
83+
84+
# By default, the client reads the API key from the environment variable NIGHTFALL_API_KEY
85+
nightfall = Nightfall()
86+
87+
# A rule contains a set of detectors to scan with
88+
detection_rule = DetectionRule([
89+
Detector(min_confidence=Confidence.LIKELY, nightfall_detector="CREDIT_CARD_NUMBER"),
90+
Detector(min_confidence=Confidence.POSSIBLE, nightfall_detector="US_SOCIAL_SECURITY_NUMBER"),
91+
])
92+
93+
94+
# Upload the file and start the scan.
95+
# These are conducted asynchronously, so provide a webhook route to an HTTPS server to send results to.
96+
id, message = nightfall.scan_file(
97+
"./super-secret-credit-cards.pdf",
98+
"https://my-service.com/nightfall/listener",
99+
detection_rules=[detection_rule]
100+
)
101+
print("started scan", id, message)
102+
```
34103

35-
For more information on the details of this library, please refer to
36-
the [API Documentation](https://docs.nightfall.ai/).
37104
## Contributing
38105

39-
Please create an issue with a description of your problem, or open a pull request with the fix.
106+
Contributions are welcome! Open a pull request to fix a bug, or open an issue to discuss a new feature
107+
or change. Please adhere to the linting criteria expected by flake8, and be sure to add unit tests for
108+
any new functionality you add.
109+
110+
Refer to `CONTRIBUTING.md` for the full details.
111+
112+
## License
40113

41-
## Development
114+
This code is licensed under the terms of the MIT License. See [here](https://opensource.org/licenses/MIT)
115+
for more information.
116+
117+
Please create an issue with a description of your problem, or open a pull request with the fix.
118+
119+
## Development
42120

43121
### Installing Development Dependencies
44122

@@ -58,19 +136,15 @@ Unit and Integration tests can be found in the `tests/` directory. You can run t
58136

59137
You can view the code coverage report by running `coverage html` and `python3 -m http.server --directory htmlcov` after running the unit tests.
60138

61-
### Creating a Release
139+
### Creating a Release
62140

63-
Releases are automatically published to PyPI using GitHub Actions. Creating a release in GitHub will trigger a new build that will publish the latest version of this library to [PyPI](https://pypi.org/project/nightfall/).
141+
Releases are automatically published to PyPI using GitHub Actions. Creating a release in GitHub will trigger a new build that will publish the latest version of this library to [PyPI](https://pypi.org/project/nightfall/).
64142

65-
The steps to do this are:
143+
The steps to do this are:
66144

67145
1. Add what changed to the CHANGELOG file
68146
2. Update the version in `setup.py`
69-
3. Commit changes and push to the main branch.
70-
4. Create a new release in the GitHub UI.
71-
5. Observe the release action succeed and see the latest version of this library on PyPI.
72-
## License
73-
74-
MIT
75-
147+
3. Commit changes and push to the main branch.
148+
4. Create a new release in the GitHub UI.
149+
5. Observe the release action succeed and see the latest version of this library on PyPI.
76150

nightfall/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def __init__(self, key: Optional[str] = None, signing_secret: Optional[str] = No
4545

4646
self._headers = {
4747
"Content-Type": "application/json",
48-
"User-Agent": "nightfall-python-sdk/1.0.0",
48+
"User-Agent": "nightfall-python-sdk/1.1.0",
4949
'Authorization': f'Bearer {self.key}',
5050
}
5151
self.signing_secret = signing_secret

nightfall/detection_rules.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ def as_dict(self):
124124
"charsToIgnore": self.chars_to_ignore
125125
}
126126

127+
127128
@dataclass
128129
class RedactionConfig:
129130
"""An object that configures how any detected findings should be redacted when returned to the client. When this

tests/test_api.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import datetime
21
import os
3-
import time
42

53
from freezegun import freeze_time
64
import pytest

0 commit comments

Comments
 (0)