Models
Attachment
Bases: Struct
Represents an attachment with its content and name.
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
from_json
classmethod
to_json
Serialize the Attachment instance into a JSON string.
The content
(binary data) will be a base64 encoded string in the JSON output.
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 Attachment. |
Source code in src/privatebin/_models.py
Paste
Bases: Struct
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 the Paste 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: Struct
Represents a parsed PrivateBin URL, including its components and delete token.
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.
delete_token
instance-attribute
delete_token: str
The delete token. Authorizes deletion of the paste.
to_str
to_str() -> str
Explicitly convert the instance into a complete, unmasked URL string.
This method behaves differently from implicit Python string conversions
like print(url)
, or f-strings (f"{url}"
).
to_str()
returns the full, unmasked URL with the sensitive passphrase.- Implicit conversions (
print()
, f-strings, etc.) return a masked URL for safety.
Call to_str()
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", delete_token="deltoken")
>>> url.to_str()
'https://example.privatebin.com/?pasteid#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#********'
Source code in src/privatebin/_models.py
from_json
classmethod
to_json
Serialize the PrivateBinUrl 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 PrivateBinUrl. |
Notes
This method includes the sensitive passphrase
in the JSON output.
It also adds an extra field named "url"
to the JSON, which is not part of
PrivateBinUrl
but is generated using the to_str()
method for convenience.