Models
Attachment
Bases: JsonStruct
Represents an attachment with its content and name.
from_json
classmethod
to_json
Serialize this instance into a JSON string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
indent
|
int
|
Number of spaces for indentation. Set to 0 for a single line with spacing, or negative to minimize size by removing extra whitespace. |
2
|
Returns:
Type | Description |
---|---|
str
|
JSON string representing the Paste. |
Source code in src/privatebin/_models.py
from_file
classmethod
Create an Attachment
instance from a file path.
If a name is not provided, the filename from the path is used as the attachment name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file
|
str | PathLike[str]
|
Path to the file from which to create the attachment. |
required |
name
|
str | None
|
The desired name for the attachment. If |
None
|
Returns:
Type | Description |
---|---|
Self
|
|
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If the provided |
Source code in src/privatebin/_models.py
from_data_url
classmethod
Create an Attachment from a data URL.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url
|
str
|
Attachment content as a data URL. |
required |
name
|
str
|
The desired name for the attachment. |
required |
Returns:
Type | Description |
---|---|
Self
|
|
Raises:
Type | Description |
---|---|
ValueError
|
If the provided |
Source code in src/privatebin/_models.py
to_data_url
to_data_url() -> str
Convert the Attachment's binary content to a data URL.
Returns:
Type | Description |
---|---|
str
|
A data URL representing the attachment content. |
Source code in src/privatebin/_models.py
Paste
Bases: JsonStruct
Represents a PrivateBin paste.
attachment
instance-attribute
attachment: Attachment | None
Attachment associated with the paste, if any.
open_discussion
instance-attribute
open_discussion: bool
Indicates if open discussions are enabled for this paste.
burn_after_reading
instance-attribute
burn_after_reading: bool
Indicates if the paste is set to be burned after the first read.
time_to_live
instance-attribute
time_to_live: timedelta | None
Time duration for which the paste is set to be stored, if any.
from_json
classmethod
to_json
Serialize this instance into a JSON string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
indent
|
int
|
Number of spaces for indentation. Set to 0 for a single line with spacing, or negative to minimize size by removing extra whitespace. |
2
|
Returns:
Type | Description |
---|---|
str
|
JSON string representing the Paste. |
Source code in src/privatebin/_models.py
PasteReceipt
Bases: JsonStruct
Represents the result of a paste creation.
from_json
classmethod
to_json
Serialize this instance into a JSON string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
indent
|
int
|
Number of spaces for indentation. Set to 0 for a single line with spacing, or negative to minimize size by removing extra whitespace. |
2
|
Returns:
Type | Description |
---|---|
str
|
JSON string representing the Paste. |
Source code in src/privatebin/_models.py
PrivateBinUrl
Bases: JsonStruct
Represents a PrivateBin URL.
id
instance-attribute
id: str
The unique paste ID. This identifies the specific paste on the server.
passphrase
instance-attribute
passphrase: str
The decryption passphrase. This is needed to decrypt and view encrypted pastes.
from_json
classmethod
to_json
Serialize this instance into a JSON string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
indent
|
int
|
Number of spaces for indentation. Set to 0 for a single line with spacing, or negative to minimize size by removing extra whitespace. |
2
|
Returns:
Type | Description |
---|---|
str
|
JSON string representing the Paste. |
Source code in src/privatebin/_models.py
unmask
unmask() -> str
Explicitly convert this instance into a complete, unmasked URL string.
This method behaves differently from implicit Python string conversions
like print(url)
, or f-strings (f"{url}"
).
unmask()
returns the full, unmasked URL with the sensitive passphrase.- Implicit conversions (
print()
, f-strings, etc.) return a masked URL for safety.
Call unmask()
when you explicitly need the full, working URL, for example, to:
- Open the URL in a browser.
- Pass the URL to a function that requires the unmasked passphrase.
Returns:
Type | Description |
---|---|
str
|
The full, unmasked PrivateBin URL. |
Examples:
>>> url = PrivateBinUrl(server="https://example.privatebin.com/", id="pasteid", passphrase="secret")
>>> print(url) # Implicit string conversion - masked URL
'https://example.privatebin.com/?pasteid#********'
>>> f"{url}" # Implicit string conversion in f-string - masked URL
'https://example.privatebin.com/?pasteid#********'
>>> url.unmask()
'https://example.privatebin.com/?pasteid#secret'
Source code in src/privatebin/_models.py
parse
classmethod
parse(url: str | PrivateBinUrl | PasteReceipt) -> Self
Parse a URL-like object into a PrivateBinUrl
instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url
|
str | PrivateBinUrl | PasteReceipt
|
The URL-like object to parse. |
required |
Returns:
Type | Description |
---|---|
Self
|
|
Raises:
Type | Description |
---|---|
ValueError
|
If the provided 'url' string is not in the expected format. |
TypeError
|
If the provided 'url' is not in the expected type. |