Skip to main content

A Python package for managing books in Shopify

Project description

Shopify Book Service

The Shopify Book Service is a Python library for managing books in a Shopify store. It provides a simple interface for performing CRUD (Create, Read, Update, Delete) operations on books, as well as for setting up and managing metafields for books.

Installation

To install the Shopify Book Service, run the following command:

pip install bluetree-shopify-book

Usage

To use the Shopify Book Service, you first need to create an instance of the ShopifyBookService class with your shop's URL and API access token:

from bluetree_shopify_book import ShopifyBookService

shop_url = "https://yourshopdomain.myshopify.com"
admin_api_access_token = "YOUR_ACCESS_TOKEN"

book_service = ShopifyBookService(shop_url, admin_api_access_token)

Note that the ShopifyBookService class uses a context manager, so you can use it in a with statement to automatically activate and clear the Shopify session:

with ShopifyBookService(shop_url, admin_api_access_token) as book_service:
    # do something with book_service

Getting a Book

To get a book by ID, use the get_book_by_id() method:

book = book_service.get_book_by_id(8148173881647)

To get a book by ISBN, use the get_book_by_isbn() method:

book = book_service.get_book_by_isbn("9780141439846")

Creating a Book

To create a book, use the create_book() method:

from src.schema import CreateBookInput

book_input = CreateBookInput(
    title="Pride and Prejudice",
    author="Jane Austen",
    description="A classic novel about love and social status.",
    price="12.99",
    sku="9780141439846",
    published_date="1813-01-28",
)

book = book_service.create_book(book_input)

To create multiple books concurrently, use the create_books() method:

from src.schema import CreateBookInput

book_inputs = [
    CreateBookInput(
        title="Pride and Prejudice",
        author="Jane Austen",
        description="A classic novel about love and social status.",
        price="12.99",
        sku="9780141439846",
        published_date="1813-01-28",
    ),
    CreateBookInput(
        title="To Kill a Mockingbird",
        author="Harper Lee",
        description="A powerful novel about race and justice in the American South.",
        price="14.99",
        sku="9780061120084",
        published_date="1960-07-11",
    ),
]

books = book_service.create_books(book_inputs)

Updating a Book

To update a book's price, use the update_book_price() method:

from decimal import Decimal

book_variant_id = 1234567890
new_price = Decimal("14.99")

book = book_service.update_book_price(book_variant_id, new_price)

Deleting a Book

To delete a book, use the delete_book() method:

book_id = 1234567890

book_service.delete_book(book_id)

Setting up Metafield Definitions

To set up default metafield definitions for books, use the setup_default_metafield_definitions() method:

book_service.setup_default_metafield_definitions()

Getting Metafield Definitions

To get all metafield definitions for books, use the _get_metafield_definitions() method:

metafield_definitions = book_service

The MIT License (MIT)

Copyright, 2023 Shinsuke Ikegame.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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

bluetree_shopify_book-0.2.3.tar.gz (12.5 kB view details)

Uploaded Source

Built Distribution

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

bluetree_shopify_book-0.2.3-py3-none-any.whl (13.3 kB view details)

Uploaded Python 3

File details

Details for the file bluetree_shopify_book-0.2.3.tar.gz.

File metadata

  • Download URL: bluetree_shopify_book-0.2.3.tar.gz
  • Upload date:
  • Size: 12.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.13

File hashes

Hashes for bluetree_shopify_book-0.2.3.tar.gz
Algorithm Hash digest
SHA256 c782ef6ad96009e19f9a34d1a18b78386ed8cef32a8af796178279c70feb19d1
MD5 edde29882d598634103eac9c7c688587
BLAKE2b-256 549e5eaffa2765f78ea449cb946cd2b8f7f84599b43138d252398efc21809af1

See more details on using hashes here.

File details

Details for the file bluetree_shopify_book-0.2.3-py3-none-any.whl.

File metadata

File hashes

Hashes for bluetree_shopify_book-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 a5337217047e7ceb2abacddcb6068f05188d80ba960ff7b2035194b2a7e004bd
MD5 d1d024c9a68d2af19ec9b2ef8d5d616c
BLAKE2b-256 69f86c37e5d77a7b26ad30ed4be08acb46ea4f73660481c456ac3aaab48dff75

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