mboauth2 package

Submodules

Module contents

OAuth2 client for MusicBrainz API.

See https://musicbrainz.org/doc/Development/OAuth2

class mboauth2.AccessType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: str, Enum

Access types for the MusicBrainz OAuth2 API.

OFFLINE = 'offline'

Access when the user is not present at the browser.

ONLINE = 'online'

Access when the user is present at the browser.

class mboauth2.AuthClient(client_id: str, client_secret: str, redirect_uri: str, session: Session | None = None)[source]

Bases: object

OAuth2 client for helping with obtaining api token.

See https://musicbrainz.org/doc/Development/OAuth2

generate_auth_url(scopes: list[str] | None = None, state: str = '', access_type: str = AccessType.OFFLINE, approval_prompt: str = ApprovalPrompt.AUTO) str[source]

Generates the authorization url for the user to follow.

refresh_token(refresh_token: str, token_type: str = '') Token[source]

Refreshes the token.

retrieve_token(code: str, token_type: str = '') Token[source]

Retrieves the token for the user once they have followed the authorization url.

class mboauth2.Scope(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: str, Enum

Scopes for the MusicBrainz OAuth2 API.

COLLECTION = 'collection'

View and modify the user’s private collections.

EMAIL = 'email'

View the user’s email.

PROFILE = 'profile'

View the user’s public profile information

RATING = 'rating'

View and modify the user’s private ratings.

SUBMIT_BARCODE = 'submit_barcode'

Submit barcodes to the database.

SUBMIT_ISRC = 'submit_isrc'

Submit new ISRCs to the database.

TAG = 'tag'

View and modify the user’s private tags.

class mboauth2.Token(access_token: str, expires_in: int, token_type: str, refresh_token: str, last_refresh: ~datetime.datetime = <factory>)[source]

Bases: object

bearer token for the MusicBrainz API.

access_token: str
property expired: bool

Returns True if the token is expired, False otherwise.

expires_in: int
last_refresh: datetime
refresh(force: bool = False) Token[source]

Refreshes the token if it is expired.

refresh_token: str
token_type: str

mboauth2.app module

MusicBrainz OAuth2 API client and helpers.

class mboauth2.app.AccessType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: str, Enum

Access types for the MusicBrainz OAuth2 API.

OFFLINE = 'offline'

Access when the user is not present at the browser.

ONLINE = 'online'

Access when the user is present at the browser.

class mboauth2.app.ApprovalPrompt(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: str, Enum

Approval prompts for the MusicBrainz OAuth2 API.

AUTO = 'auto'

The user should only be prompted for consent the first time through the sequence.

FORCE = 'force'

The user should be prompted for consent every time.

class mboauth2.app.AuthClient(client_id: str, client_secret: str, redirect_uri: str, session: Session | None = None)[source]

Bases: object

OAuth2 client for helping with obtaining api token.

See https://musicbrainz.org/doc/Development/OAuth2

generate_auth_url(scopes: list[str] | None = None, state: str = '', access_type: str = AccessType.OFFLINE, approval_prompt: str = ApprovalPrompt.AUTO) str[source]

Generates the authorization url for the user to follow.

refresh_token(refresh_token: str, token_type: str = '') Token[source]

Refreshes the token.

retrieve_token(code: str, token_type: str = '') Token[source]

Retrieves the token for the user once they have followed the authorization url.

class mboauth2.app.GrantType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: str, Enum

Grant types for the MusicBrainz OAuth2 API.

AUTHORIZATION_CODE = 'authorization_code'
REFRESH_TOKEN = 'refresh_token'
class mboauth2.app.Scope(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: str, Enum

Scopes for the MusicBrainz OAuth2 API.

COLLECTION = 'collection'

View and modify the user’s private collections.

EMAIL = 'email'

View the user’s email.

PROFILE = 'profile'

View the user’s public profile information

RATING = 'rating'

View and modify the user’s private ratings.

SUBMIT_BARCODE = 'submit_barcode'

Submit barcodes to the database.

SUBMIT_ISRC = 'submit_isrc'

Submit new ISRCs to the database.

TAG = 'tag'

View and modify the user’s private tags.

class mboauth2.app.Token(access_token: str, expires_in: int, token_type: str, refresh_token: str, last_refresh: ~datetime.datetime = <factory>)[source]

Bases: object

bearer token for the MusicBrainz API.

access_token: str
property expired: bool

Returns True if the token is expired, False otherwise.

expires_in: int
last_refresh: datetime
refresh(force: bool = False) Token[source]

Refreshes the token if it is expired.

refresh_token: str
token_type: str