Models
Attachment
¶
Bases: JsonStruct
Represents an attachment with its content and name.
from_json
classmethod
¶
from_json(data: str) -> Self
Create an instance of this class from a JSON string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
str
|
JSON string representing the Paste instance. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
|
Source code in src/privatebin/_models.py
to_json
¶
to_json() -> str
Serialize this instance into a JSON string.
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.
attachments
instance-attribute
¶
attachments: tuple[Attachment, ...]
Attachments associated with the paste.
feature
class-attribute
instance-attribute
¶
feature: Feature | None = None
The feature applied to the paste.
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
¶
from_json(data: str) -> Self
Create an instance of this class from a JSON string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
str
|
JSON string representing the Paste instance. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
|
Source code in src/privatebin/_models.py
PasteReceipt
¶
Bases: JsonStruct
Represents the result of a paste creation.
from_json
classmethod
¶
from_json(data: str) -> Self
Create an instance of this class from a JSON string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
str
|
JSON string representing the Paste instance. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
|
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
¶
from_json(data: str) -> Self
Create an instance of this class from a JSON string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
str
|
JSON string representing the Paste instance. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
|
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
to_json
¶
to_json() -> str
Serialize this instance into a JSON string.
Returns:
| Type | Description |
|---|---|
str
|
JSON string representing the URL. |
Warnings
The serialized JSON contains the passphrase in plain text.
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. |