Skip to main content

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 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

This library supports connecting to any Ampache API release (3, 4, 5, 6 and 8)

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 sys
import time

# Open Ampache library
ampache_connection = ampache.API()

# Set your server details
# AMPACHE_VERSION now defaults to 8.1.1, so if your server is on
# API6 (or older) call set_version() with your server's version
ampache_connection.set_version('6.6.1')
ampache_connection.set_url('https://music.com.au')
ampache_connection.set_key('mypassword')
ampache_connection.set_user('myusername')

# Password auth requires a timestamp for encrypting the auth key
ampache_session = ampache_connection.execute('handshake', {'timestamp': int(time.time())})
if not ampache_session:
    # if using an api key you don't need the timestamp to use encrypt_string
    ampache_session = ampache_connection.execute('handshake')

# Fail if you didn't connect
if not ampache_session:
    sys.exit(ampache_connection.AMPACHE_VERSION + ' ERROR Failed to connect to ' + ampache_connection.AMPACHE_URL)

# now you can call methods without having to keep putting in the url and userkey
artists = ampache_connection.execute('artists', {'limit': 10})

# You can parse a response to get a list of ID's for that response
artist_ids = ampache_connection.get_id_list(artists, 'artist')
if artist_ids:
    print("We found some artists")
    for artist in artist_ids:
        print('ID:', artist)

# ping has always allowed empty calls so you have to ping with a session key
ampache_connection.execute('ping', {'ampache_api': ampache_session})

NEWS

  • 8.1.1 adds support for Ampache API8: folders, album disks, playlist folders, collections, and a type-aware playlist_remove. See CHANGELOG.md for the full list.

  • 8.1.1 breaking changes affecting all callers regardless of server API version:

    • AMPACHE_VERSION now defaults to 8.1.1 instead of 6.9.0 — call set_version() explicitly if you’re on an older API.

    • HTTP error responses are returned instead of False (call set_return_http_errors(False) to restore the old behavior).

    • users(), stream(), download() and get_indexes() changed parameter order — positional callers must update their call sites, keyword callers are unaffected.

  • get_indexes, playlist_add_song, playlist_remove_song and user_update are deprecated in favor of index, playlist_add, playlist_remove and user_edit.

  • Examples are being updated to support the latest execute method which can simplify your code

  • 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, list, 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 6.x.x+ to scrobble a track to your server

import ampache
import sys
import time

# Open Ampache library
ampache_connection = ampache.API()

# load up previous config
if not ampache_connection.get_config():
    # Set your details manually if we can't get anything
    # use your server's own API version here (defaults to 8.1.1)
    ampache_connection.set_version('6.6.1')
    ampache_connection.set_url('https://music.server')
    ampache_connection.set_key('mysuperapikey')
    ampache_connection.set_user('myusername')

# Get a session key using the handshake
#
# * ampache_url = (string) Full Ampache URL e.g. 'https://music.com.au'
# * ampache_api = (string) encrypted apikey OR password if using password auth
# * user        = (string) username //optional
# * timestamp   = (integer) UNIXTIME() //optional
# * version     = (string) API Version //optional
ampache_session = ampache_connection.execute('handshake')

# Fail if you didn't connect
if not ampache_session:
    sys.exit(ampache_connection.AMPACHE_VERSION + ' ERROR Failed to connect to ' + ampache_connection.AMPACHE_URL)

# save your successful connection in your local config
ampache_connection.save_config()

# Scrobble a music track to your ampache server
#
# * title       = (string) song title
# * artist_name = (string) artist name
# * album_name  = (string) album name
# * mbtitle     = (string) song mbid //optional
# * mbartist    = (string) artist mbid //optional
# * mbalbum     = (string) album mbid //optional
# * stime       = (integer) UNIXTIME() //optional
# * client      = (string) //optional
ampache_connection.execute('scrobble', {'title': 'Beneath The Cold Clay',
                                        'artist_name': 'Crust',
                                        'album_name': '...and a Dirge Becomes an Anthem',
                                        'stime': int(time.time())})

POWERED BY

PhpStorm logo
https://resources.jetbrains.com/storage/products/company/brand/logos/PyCharm.png

JetBrains have supported the project for many years now and their tools really do power Ampache development.

Metadata

Release files for ampache 8.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ampache 8.3.0
File Size Uploaded Provenance Actions
ampache-8.3.0.tar.gz 50.4 kB With provenance Details for ampache-8.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ampache 8.3.0
File Interpreter ABI Platform Actions
ampache-8.3.0-py3-none-any.whl Python 3 none any Details for ampache-8.3.0-py3-none-any.whl

Total release size: 101.0 kB

Release files / ampache-8.3.0.tar.gz

Download URL ampache-8.3.0.tar.gz
Size 50.4 kB
Tags Source
SHA-256 checksum
How to use checksums
4603a02f7b1e24692779f92e035f5a94eca55d2ac3bcc81d4ced1f4f79a0d650
BLAKE2b-256 checksum
How to use checksums
0eaee1555e78bd886419d50fcec0eb0e0274d4918a33f575db06dfce0a28201a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 20, 2026.

Transparency log

Release files / ampache-8.3.0-py3-none-any.whl

Download URL ampache-8.3.0-py3-none-any.whl
Size 50.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f68ad27bfbe52ea474ba108b8a74b723cf9a1e89f3dc1da30b49bfc52de1fa2a
BLAKE2b-256 checksum
How to use checksums
0c71c216de5b232ce199ef18b9014d9c70e88c55857b66aa442db3b150eb9a5d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 20, 2026.

Transparency log

Security for ampache 8.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for ampache-8.3.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 20, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

8.3.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page