Skip to main content

Python library for Amapche XML & JSON API

Project description

AMPACHE LIBRARY FOR PYTHON3

Upload to PyPI
https://github.com/ampache/python3-ampache/workflows/Upload%20Python%20Package/badge.svg

INFO

A python3 library for interaction with your Ampache 5.x.x server using the XML & JSON API

https://ampache.org/API/

Code examples and scripts are available from github

The class documentation has been extracted out into a markdown file for easier reading.

https://raw.githubusercontent.com/ampache/python3-ampache/master/docs/MANUAL.md

There has been a pretty significant change in the library between Ampache 4 and Ampache 5.

For anyone wanting to stay on v4 the branch has been separated from the master branch.

https://github.com/ampache/python3-ampache/tree/api4

Once you connect with your passphrase or api key, the url and auth token are stored allowing you to call methods without them.

import ampache
import time

# connect to the server
ampacheConnection = ampache.API()

# if using password auth use encrypt_password
mytime = int(time.time())
passphrase = ampacheConnection.encrypt_password('mypassword', mytime)
auth = ampacheConnection.handshake('https://music.com.au', passphrase, 'my username', mytime)

# if using an API key auth keep using encrypt_string
passphrase = ampacheConnection.encrypt_string('my apikey', 'my username')
auth = ampacheConnection.handshake('https://music.com.au', passphrase)

# now you can call methods without having to keep putting in the url and userkey
ampacheConnection.label(1677)

# ping has always allowed empty calls so you have to ping with a url and session still
ampacheConnection.ping('https://music.com.au', auth)

NEWS

  • Password handshake auth is available now.

  • This library only supports Ampache 5+ with a lot of significant change on the Ampache and library side

INSTALL

You can now install from pip directly:

pip3 install -U ampache

EXAMPLES

There is a fairly simple cli example for windows/linux to perform a few functions. It’s a good example for testing and might make things a bit easier to follow.

https://raw.githubusercontent.com/ampache/python3-ampache/master/docs/examples/ampyche.py

ampyche.py help:

Possible Actions:

    /u:%CUSTOM_USER%    (Custom username for the current action)
    /k:%CUSTOM_APIKEY%  (Custom apikey for the current action)
    /a:%ACTION%         (ping, playlists, localplay, download, configure, logout, showconfig)
    /l:%LIMIT%          (integer)
    /o:%OBJECT_ID%      (string)
    /t:%OBJECT_TYPE%    (song, playlist)
    /p:%PATH%           (folder for downloads)
    /f:%FORMAT%         (raw, mp3, ogg, flac)
    /usb                (split files into numeric 0-9 folders for car USBs)
    /c:%COMMAND%        (localplay command)
    (next, prev, stop, play, pause, add, volume_up,
        volume_down, volume_mute, delete_all, skip, status)

Here is a short code sample for python to scrobble a track to your server

import time
import ampache

# user variables
ampache_url = 'https://music.server'
my_api_key = 'mysuperapikey'
user = 'myusername'

# processed details
encrypted_key = ampache.encrypt_string(my_api_key, user)
ampache_session = ampache.handshake(ampache_url, encrypted_key)

if ampache_session:
    # Scrobble a music track to your ampache server
    Process(target=ampache.scrobble,
            args=(ampache_url, ampache_session,
                  'Hear.Life.Spoken', 'Sub Atari Knives', 'Unearthed',
                  '', '', int(time.time()))).start()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ampache-5.1.0.tar.gz (27.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ampache-5.1.0-py3-none-any.whl (27.5 kB view details)

Uploaded Python 3

File details

Details for the file ampache-5.1.0.tar.gz.

File metadata

  • Download URL: ampache-5.1.0.tar.gz
  • Upload date:
  • Size: 27.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for ampache-5.1.0.tar.gz
Algorithm Hash digest
SHA256 2ffc46aa3261bea3fad84e7454486b2550bc94116517b8a7b2f24c28985a5ca3
MD5 36ff27b443c8c532aee6a3ef2f3c9c5d
BLAKE2b-256 c39b76a9c5f03556987d7d7872d346ce0cafc615a3ca591a48aa8d0589b27c98

See more details on using hashes here.

File details

Details for the file ampache-5.1.0-py3-none-any.whl.

File metadata

  • Download URL: ampache-5.1.0-py3-none-any.whl
  • Upload date:
  • Size: 27.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for ampache-5.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1497c748b056f6fff21dddf4a967d1eabdd3aa3156fae30703a7909b91b0dbea
MD5 f9f9fb29c20981ae610a4da61af26b44
BLAKE2b-256 ff9e27baf09ce54525bef22ae93b07d19ce66db45068a2c49b7e3ade46027cdf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page