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 now supports every Ampache API release (3, 4 and 5)

  • You can save and restore from a json config file using new methods * set_config_path: Set a folder to your config path * get_config: Load the config and set Ampache globals * save_config: Save the config file with the current globals

AMPACHE_URL = The URL of your Ampache server AMPACHE_USER = config[“ampache_user”] AMPACHE_KEY = Your encrypted apikey OR password if using password auth AMPACHE_SESSION = Current session auth from the handshake. Use to reconnect to an existing session AMPACHE_API = API output format “json” || “xml”

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 using version 5.x.x+ 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
ampacheConnection = ampache.API()
encrypted_key = ampacheConnection.encrypt_string(my_api_key, user)
ampache_session = ampacheConnection.handshake(ampache_url, encrypted_key)

if ampache_session:
    # Scrobble a music track to your ampache server
    Process(target=ampacheConnection.scrobble,
            args=('Beneath The Cold Clay', 'Crust', '...and a Dirge Becomes an Anthem',
                  '', '', '', 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-6.0.0.tar.gz (30.3 kB view details)

Uploaded Source

Built Distribution

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

ampache-6.0.0-py3-none-any.whl (30.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ampache-6.0.0.tar.gz
  • Upload date:
  • Size: 30.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for ampache-6.0.0.tar.gz
Algorithm Hash digest
SHA256 a5decb10ccaefaac782c4c2a84e7c42accc229a1cc71a4105cf5c022986d2a9a
MD5 896c0e542d25eaa25bae57f2b979c469
BLAKE2b-256 9306e03aa4138e75c7b4577eaa094345a5d5e24a239c7b3a1863456b9143c683

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ampache-6.0.0-py3-none-any.whl
  • Upload date:
  • Size: 30.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for ampache-6.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 810c6f3313aa3e202b98452f24659ad7ad1e3d0312bb0eaca0b26b5e6af7dd49
MD5 9760ff55ec64f20ead88d9c5f50ee334
BLAKE2b-256 4fbc92cda77d2a42c144948f089d25794567f463d312cc94566d95e5c510470d

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