Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion concepts/secrets/.meta/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"blurb": "The secrets module is a cryptographically-secure alternative to the random module, intended for security-critical uses.",
"authors": ["BethanyG", "colinleach"],
"contributors": []
"contributors": ["yrahcaz7"]
}
18 changes: 7 additions & 11 deletions concepts/secrets/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,41 @@ The [`secrets`][secrets] module overlaps with `random` in some of its functional
- `random` is optimized for high performance in modelling and simulation, with "good enough" pseudo-random number generation.
- `secrets` is designed to be crytographically secure for applications such as password hashing, security token generation, and account authentication.


Further details on why the addition of the `secrets` module proved necessary are given in [PEP 506][PEP506].

The `secrets` is relatively small and straightforward, with methods for generating random integers, bits, bytes or tokens, or a random entry from a given sequence.

To use `scerets`, you mush first `import` it:
The `secrets` module is relatively small and straightforward, with methods for generating random integers, bits, bytes, tokens, or a random entry from a given sequence.

To use `secrets`, you must first `import` it:

```python
>>> import secrets

#Returns n, where 0 <= n < 1000.
# Returns n, where 0 <= n < 1000.
>>> secrets.randbelow(1000)
577

#32-bit integers.
# 32-bit integers.
>>> secrets.randbits(32)
3028709440

>>> bin(secrets.randbits(32))
'0b11111000101100101111110011110100'

#Pick at random from a sequence.
# Pick at random from a sequence.
>>> secrets.choice(['my', 'secret', 'thing'])
'thing'

#Generate a token made up of random hexadecimal digits.
# Generate a token made up of random hexadecimal digits.
>>> secrets.token_hex()
'f683d093ea9aa1f2607497c837cf11d7afaefa903c5805f94b64f068e2b9e621'

#Generate a URL-safe token of random alphanumeric characters.
# Generate a URL-safe token of random alphanumeric characters.
>>> secrets.token_urlsafe(16)
'gkSUKRdiPDHqmImPi2HMnw'
```


If you are writing security-sensitive applications, you will certainly want to read the [full documentation][secrets], which gives further advice and examples.


[PEP506]: https://peps.python.org/pep-0506/
[pseudo-random-numbers]: https://www.khanacademy.org/computing/computer-science/cryptography/crypt/v/random-vs-pseudorandom-number-generators
[secrets]: https://docs.python.org/3/library/secrets.html
1 change: 0 additions & 1 deletion concepts/secrets/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ The [`secrets`][secrets] module overlaps with `random` in some of its functional
- `random` is optimized for high performance in modelling and simulation, with "good enough" pseudo-random number generation.
- `secrets` is designed to be crytographically secure for applications such as password hashing, security token generation, and account authentication.


Further details on why the addition of the `secrets` module proved necessary are given in [PEP 506][PEP506].

If you are writing security-sensitive applications, you will certainly want to read the [full documentation][secrets], which gives further advice and examples.
Expand Down
5 changes: 3 additions & 2 deletions concepts/string-formatting/.meta/config.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"blurb": "There are four main string formatting methods. A '%' formatting mini-language is supported, but is considered outdated. String interpolation (f-strings) and 'str.format()'are newer, and can be used for complex or conditional substitution. 'string.template()' substitution is used for internationalization, where f-strings will not translate.",
"blurb": "There are four main string formatting methods. A '%' formatting mini-language is supported, but is considered outdated. String interpolation (f-strings) and 'str.format()' are newer, and can be used for complex or conditional substitution. 'string.Template()' substitution is used for internationalization, where f-strings will not translate.",
"authors": [
"valentin-p"
],
"contributors": [
"j08k",
"BethanyG",
"BNAndras"
"BNAndras",
"yrahcaz7"
]
}
Loading
Loading