Models¶
API¶
-
class
API(api_key, access_token=None, base_url='https://crabber.net', base_endpoint='/api/v1')¶ Establishes a connection with an instance of Crabber.
This can connect to any fork of Crabber, including one running on your local machine.
- Parameters
api_key (
str) – Your developer key obtained from the developer page on your target instance of Crabber.access_token (
Optional[str]) – Your access token obtained from the developer page on your target instance of Crabber. This is only for authenticated endpoints and can be omitted. It can also be provided after instantiating the API using API.authenticate.base_url (
str) – The URL of the instance of Crabber you want to connect to.base_endpoint (
str) – The API endpoint to use when making requests. At the current time there is no reason to change this as ‘/api/v1’ is the only compliant endpoint.
Warning
You must provide a protocol (either ‘http://’ or ‘https://’) in base_url otherwise connection will fail.
-
authenticate(access_token)¶ Establishes authentication with the server. This can be used to declare an access_token after instantiating API.
- Parameters
access_token (
str) – Your access token obtained from the developer page on your target instance of Crabber. This is only for authenticated endpoints and can be omitted. It can also be provided after instantiating the API using API.authenticate.- Return type
bool- Returns
Bool denoting whether authentication was successful.
-
get_crab(crab_id)¶ Get a Crab by its ID.
- Parameters
crab_id (
int) – The ID of the Crab to return.- Return type
Optional[Crab]- Returns
Crab with crab_id if one exists.
-
get_crab_by_username(username)¶ Get a Crab by its username.
- Parameters
username (
str) – The username of the Crab to return.- Return type
Optional[Crab]- Returns
Crab with username if one exists.
-
get_current_user()¶ Get the current authenticated user.
- Return type
Optional[Crab]- Returns
Crab if currently authenticated.
-
get_molt(molt_id)¶ Get a Molt by its ID.
- Parameters
molt_id (
int) – The ID of the Molt to return.- Return type
Optional[Molt]- Returns
Molt with molt_id if one exists.
-
get_molts_mentioning(username, limit=10, offset=0, since_ts=None, since_id=None)¶ Get all valid Molts that mention a certain username.
- Parameters
username (
str) – The username to search for.limit (
int) – Maximum number of results to return, defaults to 10. Max: 50.offset (
int) – How many Molts to skip before applying the limit, defaults to 0.since_ts (
Optional[int]) – Only return Molts that were posted after this timestamp (UTC).since_id (
Optional[int]) – Only return Molts whose ID is greater than this.
- Return type
List[Molt]- Returns
List of Molts found.
Note
This only searches for usernames explicitly mentioned with ‘@username’ and will not return Molts that just include the username in their content.
-
get_molts_replying_to(username, limit=10, offset=0, since_ts=None, since_id=None)¶ Get all valid Molts that are replying to Molts posted by a certain username.
- Parameters
username (
str) – The username to search for.limit (
int) – Maximum number of results to return, defaults to 10. Max: 50.offset (
int) – How many Molts to skip before applying the limit, defaults to 0.since_ts (
Optional[int]) – Only return Molts that were posted after this timestamp (UTC).since_id (
Optional[int]) – Only return Molts whose ID is greater than this.
- Return type
List[Molt]- Returns
List of Molts found.
-
get_molts_with_crabtag(crabtag, limit=10, offset=0, since_ts=None, since_id=None)¶ Get all valid Molts that use a certain crabtag.
- Parameters
crabtag (
str) – The crabtag to search for.limit (
int) – Maximum number of results to return, defaults to 10. Max: 50.offset (
int) – How many Molts to skip before applying the limit, defaults to 0.since_ts (
Optional[int]) – Only return Molts that were posted after this timestamp (UTC).since_id (
Optional[int]) – Only return Molts whose ID is greater than this.
- Return type
List[Molt]- Returns
List of Molts found.
-
post_molt(content, image_path=None)¶ Post new Molt as the authenticated user.
- Parameters
content (
str) – The text content of the Molt to post.image_path (
Optional[str]) – The path to a valid image file that will be uploaded and included in this Molt.
- Return type
Optional[Molt]- Returns
The posted Molt if successful.
- Raises
FileNotFoundError, RequiresAuthenticationError, ValueError
Bio¶
-
class
Bio(crab)¶ Contains a Crab’s bio.
Warning
Do not directly instantiate this class. You can access it through Crab.bio on whatever Crab is of interest.
-
property
age¶ - Return type
Optional[str]
-
property
description¶ - Return type
Optional[str]
-
property
favorite_emoji¶ - Return type
Optional[str]
-
property
jam¶ - Return type
Optional[str]
-
property
location¶ - Return type
Optional[str]
-
property
obsession¶ - Return type
Optional[str]
-
property
pronouns¶ - Return type
Optional[str]
-
property
quote¶ - Return type
Optional[str]
-
property
remember_when¶ - Return type
Optional[str]
-
update(age=None, description=None, favorite_emoji=None, jam=None, location=None, obsession=None, pronouns=None, quote=None, remember_when=None)¶ Updates the bio of the parent Crab.
- Return type
bool
-
property
Crab¶
-
class
Crab(json, api)¶ Represents a Crabber user.
Warning
Do not directly instantiate this class. You can access it through various methods of API.
-
property
avatar¶ The URL of this Crab’s avatar image.
- Return type
str
-
property
bookmarks¶ Returns a list all Molts this Crab has bookmarked in descending order of the time at which they were bookmarked.
- Return type
List[Molt]
-
property
display_name¶ This Crab’s display name. Display names don’t have to be unique and can include spaces, emoji, and really any Unicode characters.
- Return type
str
-
follow()¶ Follow this Crab as the authenticated user.
- Return type
bool- Returns
Whether the operation was successful.
-
property
follower_count¶ The number of followers this Crab currently has.
- Return type
int
-
property
following¶ Returns a list of all the Crabs this Crab currently follows.
- Return type
List[Crab]
-
property
following_count¶ The number of Crabs this Crab currently follows.
- Return type
int
-
get_mentions(limit=10, offset=0, since_ts=None, since_id=None)¶ Get all valid Molts that mention this Crab.
- Parameters
limit (
int) – Maximum number of results to return, defaults to 10. Max: 50.offset (
int) – How many Molts to skip before applying the limit, defaults to 0.since_ts (
Optional[int]) – Only return Molts that were posted after this timestamp (UTC).since_id (
Optional[int]) – Only return Molts whose ID is greater than this.
- Return type
List[Molt]- Returns
List of Molts found.
-
get_molts(limit=10, offset=0, since_ts=None, since_id=None)¶ Get all valid Molts posted by this Crab.
- Parameters
limit (
int) – Maximum number of results to return, defaults to 10. Max: 50.offset (
int) – How many Molts to skip before applying the limit, defaults to 0.since_ts (
Optional[int]) – Only return Molts that were posted after this timestamp (UTC).since_id (
Optional[int]) – Only return Molts whose ID is greater than this.
- Return type
List[Molt]- Returns
List of Molts found.
-
get_replies(limit=10, offset=0, since_ts=None, since_id=None)¶ Get all valid Molts that reply to any of this Crab’s Molts.
- Parameters
limit (
int) – Maximum number of results to return, defaults to 10. Max: 50.offset (
int) – How many Molts to skip before applying the limit, defaults to 0.since_ts (
Optional[int]) – Only return Molts that were posted after this timestamp (UTC).since_id (
Optional[int]) – Only return Molts whose ID is greater than this.
- Return type
List[Molt]- Returns
List of Molts found.
-
property
id¶ This Crab’s ID.
- Return type
int
-
property
is_verified¶ Whether this Crab is a verified user.
Some accounts are verified when they have been confirmed to represent a person of interest who others may realistically attempt to impersonate.
- Return type
bool
-
property
register_time¶ The time at which this Crab was registered on Crabber.
- Return type
datetime
-
property
timestamp¶ The same as Crab.register_time except returned as a UTC timestamp instead of a datetime object.
- Return type
int
-
unfollow()¶ Unfollow this Crab as the authenticated user.
- Return type
bool- Returns
Whether the operation was successful.
-
property
username¶ This Crab’s username.
- Return type
str
-
property
Molt¶
-
class
Molt(json, api)¶ Represents a Crabber post.
Warning
Do not directly instantiate this class. You can access it through various methods of API, Crab, and Molt.
The Crab who posted this Molt.
- Return type
-
bookmark()¶ Bookmark this Molt as the authenticated user.
- Return type
bool- Returns
Whether this operation was successful.
-
property
content¶ The text content of this Molt.
- Return type
str
List of the crabtags used in this Molt.
- Return type
List[str]
-
property
datetime¶ The time at which this Molt was posted.
- Return type
datetime
-
delete()¶ Delete this Molt if the authenticated user is the author.
- Return type
bool- Returns
Whether this operation was successful.
-
edit(content=None, image_path=None)¶ Edit this Molt as the authenticated user.
- Parameters
content (
Optional[str]) – The text content to replace the current content with.image_path (
Optional[str]) – The path to a valid image file that will be uploaded and replace the current image.
- Return type
Optional[bool]- Returns
Whether this operation was successful.
-
property
editable¶ Whether this Molt is currently editable.
Molts are editable for the first five minutes after they are posted. Any requests to edit received by the server after that point will be rejected.
- Return type
bool
-
property
edited¶ Whether this Molt has been edited.
- Return type
bool
-
get_replies(limit=10, offset=0, since_ts=None, since_id=None)¶ Get all valid Molts that reply to this Molt.
- Parameters
limit (
int) – Maximum number of results to return, defaults to 10. Max: 50.offset (
int) – How many Molts to skip before applying the limit, defaults to 0.since_ts (
Optional[int]) – Only return Molts that were posted after this timestamp (UTC).since_id (
Optional[int]) – Only return Molts whose ID is greater than this.
- Return type
List[Molt]- Returns
List of Molts found.
-
property
id¶ This Molt’s ID.
- Return type
int
-
property
image¶ The URL of the image contained in this Molt if it exists.
- Return type
Optional[str]
-
property
is_quote¶ Whether this Molt is quoting another Molt.
- Return type
int
-
property
is_reply¶ Whether this Molt is replying to another Molt.
- Return type
int
-
like()¶ Like this Molt as the authenticated user.
- Return type
bool- Returns
Whether this operation was successful.
-
property
likes¶ The number of likes this Molt has.
- Return type
int
-
property
mentions¶ List of the usernames mentioned in this Molt.
- Return type
List[str]
-
quote(content, image_path=None)¶ Post a new Molt that quotes this one as the authenticated user.
- Parameters
content (
str) – The text content of the Molt to post.image_path (
Optional[str]) – The path to a valid image file that will be uploaded and included in this Molt.
- Return type
Optional[Molt]- Returns
The posted Molt if successful.
-
property
quoted_molt¶ The Molt that this Molt is quoting if this Molt is quoting one.
- Return type
Optional[Molt]
-
property
quotes¶ Number of Molts that quote this Molt.
- Return type
int
-
remolt()¶ Remolt this Molt if the authenticated user is the author.
- Return type
bool- Returns
Whether this operation was successful.
-
property
remolts¶ Number of Remolts this Molt has.
- Return type
int
-
reply(content, image_path=None)¶ Post a new Molt that replies to this one as the authenticated user.
- Parameters
content (
str) – The text content of the Molt to post.image_path (
Optional[str]) – The path to a valid image file that will be uploaded and included in this Molt.
- Return type
Optional[Molt]- Returns
The posted Molt if successful.
-
property
replying_to¶ The Molt that this Molt is replying to if this Molt is a reply.
- Return type
Optional[Molt]
-
property
timestamp¶ The same as Molt.datetime except returned as a UTC timestamp instead of a datetime object.
- Return type
int
-
unbookmark()¶ Unbookmark this Molt as the authenticated user.
- Return type
bool- Returns
Whether this operation was successful.
-
unlike()¶ Unlike this Molt as the authenticated user.
- Return type
bool- Returns
Whether this operation was successful.
-
unremolt()¶ Unremolt this Molt if the authenticated user is the author.
- Return type
bool- Returns
Whether this operation was successful.