Skip to main content

A Python client for the Spliit API (group expense sharing)

Project description

Spliit Client

PyPI version Python 3.7+ License: MIT

Spliit Client is a professional, well-documented Python client for the Spliit API, enabling seamless group expense sharing and management. This package is released under the permissive MIT License, making it suitable for both personal and commercial projects.

Note: This project is a fix and improvement on the work done in makp0/spliit-api-client, with enhanced structure, documentation, testing, and packaging.


Features

  • Effortlessly create and manage expense groups
  • Add and manage participants
  • Add, retrieve, and delete expenses
  • Multiple split modes: evenly, by shares, by percentage, by amount
  • Comprehensive, categorized expense types
  • Command-line interface (CLI) for quick operations
  • Type hints and robust error handling
  • Professional documentation and examples

Installation

From PyPI (Recommended)

pip install spliit_client

From Source

git clone https://github.com/abg0148/spliit_client.git
cd spliit_client
pip install -e .

Development Installation

git clone https://github.com/abg0148/spliit_client.git
cd spliit_client
pip install -e ".[dev]"

Quick Start

Basic Usage

from spliit_client import Spliit, SplitMode

# Create a new group
group = Spliit.create_group(
    name="Trip to Paris",
    currency="$",
    participants=[
        {"name": "Alice"},
        {"name": "Bob"},
        {"name": "Charlie"}
    ]
)

# Get participant IDs
participants = group.get_participants()
alice_id = participants["Alice"]

# Add an expense
expense_id = group.add_expense(
    title="Dinner",
    amount=6000,  # Amount in cents ($60.00)
    paid_by=alice_id,
    paid_for=[
        (alice_id, 1),
        (participants["Bob"], 1),
        (participants["Charlie"], 1)
    ],
    split_mode=SplitMode.EVENLY,
    notes="Dinner at a restaurant",
    category=8  # Dining Out
)

# Retrieve all expenses
expenses = group.get_expenses()
for expense in expenses:
    print(f"{expense['title']}: ${expense['amount']/100:.2f}")

Command-Line Interface (CLI)

Spliit Client provides a CLI for common operations:

# Create a new group
spliit create-group "Trip to Paris" --currency "$" --participants Alice Bob Charlie

# List all available categories
spliit list-categories

# Show version
spliit version

API Reference

Spliit Class

Class Methods

  • create_group(name, currency="$", server_url=OFFICIAL_INSTANCE, participants=None)
    • Create a new group and return a client instance.

Instance Methods

  • get_group() — Get group details
  • get_participants() — Get all participants with their IDs
  • get_username_id(name) — Get participant ID by name
  • get_expenses() — Get all expenses in the group
  • get_expense(expense_id) — Get details of a specific expense
  • add_expense(...) — Add a new expense to the group
  • remove_expense(expense_id) — Remove an expense from the group

SplitMode Enum

  • SplitMode.EVENLY: Split the expense evenly among participants
  • SplitMode.BY_SHARES: Split by number of shares per participant
  • SplitMode.BY_PERCENTAGE: Split by percentage
  • SplitMode.BY_AMOUNT: Split by specific amounts

CATEGORIES Dictionary

A comprehensive dictionary of categorized expense types. See the code for details.


Example: Trip Expense Management

from spliit_client import Spliit, SplitMode

group = Spliit.create_group(
    name="Weekend Trip to Mountains",
    currency="$",
    participants=[
        {"name": "Alice"},
        {"name": "Bob"},
        {"name": "Charlie"},
        {"name": "Diana"}
    ]
)

participants = group.get_participants()
alice_id = participants["Alice"]
bob_id = participants["Bob"]
charlie_id = participants["Charlie"]
diana_id = participants["Diana"]

# Add expenses
group.add_expense(
    title="Gas for the trip",
    amount=8000,  # $80.00
    paid_by=alice_id,
    paid_for=[(alice_id, 1), (bob_id, 1), (charlie_id, 1), (diana_id, 1)],
    split_mode=SplitMode.EVENLY,
    category=31  # Gas/Fuel
)

group.add_expense(
    title="Hotel room",
    amount=20000,  # $200.00
    paid_by=bob_id,
    paid_for=[(alice_id, 1), (bob_id, 1), (charlie_id, 1), (diana_id, 1)],
    split_mode=SplitMode.EVENLY,
    category=32  # Hotel
)

# Get all expenses
all_expenses = group.get_expenses()
print(f"Total expenses: {len(all_expenses)}")
for expense in all_expenses:
    print(f"- {expense['title']}: ${expense['amount']/100:.2f}")

Development & Contribution

Setting Up

git clone https://github.com/abg0148/spliit_client.git
cd spliit_client
pip install -e ".[dev]"

Running Tests

pytest
pytest --cov=spliit_client

Code Quality

black spliit_client tests
flake8 spliit_client tests
mypy spliit_client

Building and Publishing

python -m build
# Test upload
python -m twine upload --repository testpypi dist/*
# Production upload
python -m twine upload dist/*

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/your-feature)
  3. Commit your changes (git commit -m 'Add your feature')
  4. Push to your branch (git push origin feature/your-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License. You are free to use, modify, and distribute this software for any purpose, including commercial applications, as long as the original copyright and license notice appear in all copies.


Acknowledgments

  • Spliit for the expense sharing platform
  • makp0/spliit-api-client for the original implementation
  • The Python community for excellent tools and libraries

Support

If you encounter any issues or have questions:


Note: This is an unofficial client for the Spliit API. It is not affiliated with or endorsed by Spliit.

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

spliit_client-0.1.0.tar.gz (14.5 kB view details)

Uploaded Source

Built Distribution

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

spliit_client-0.1.0-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file spliit_client-0.1.0.tar.gz.

File metadata

  • Download URL: spliit_client-0.1.0.tar.gz
  • Upload date:
  • Size: 14.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for spliit_client-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2c2c06a355f783d68c82f14513fbda63603dd77b8f5f9ca64d7b62d8b5bfdb6e
MD5 8c1737b6e78cae60ce3870c4242bd615
BLAKE2b-256 fd4620ab7cb2c5050e4ea3b2dc98343675fdfc91b30eb04dbb02938f39bfc1d0

See more details on using hashes here.

File details

Details for the file spliit_client-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: spliit_client-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for spliit_client-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 181d3e92c51813a6d63d5d86b429cae2b6de7894c1e0afa8b896d7e50e65a696
MD5 e89b87099bab5015d89472d5e2210d48
BLAKE2b-256 ed2ceafa3e8bce51347862d553e3de80b698fb24e805eea81f2ad4de40288067

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