Skip to main content

Python wrapper for the Moloni API

Project description

PYTHON-MOLONI

Welcome to the Moloni API Client! This Python package provides a simple and flexible way to interact with the Moloni API. It supports a wide range of endpoints and allows you to manage your Moloni account programmatically.

Table of Contents

Features

  • Comprehensive Coverage: Supports all Moloni API endpoints.
  • Flexible Configuration: Easily configure and authenticate your requests.
  • Built-in Models: Utilize predefined Pydantic models for request validation.

Installation

You can install the Moloni API Client using pip:

pip install python-moloni

Documentation

Documentation is available here

Usage

Full Configuration

You can set up a fully configured client with all necessary authentication details:

from moloni.api.companies_client import CompaniesClient
from moloni.base import AuthConfig, MoloniBaseUrl
import logging

logger = logging.getLogger(__name__)

companies = CompaniesClient(
    environment=MoloniBaseUrl.PROD,
    auth_config=AuthConfig(
        client_id="your_client_id",
        client_secret="your_client_secret",
        username="your_username",  # Optional if refresh_token is set
        password="your_password",  # Optional if refresh_token is set
        refresh_token="your_refresh_token",  # Optional if username and password are set
    ),
    log_level="INFO",
    version="v1",
    validate=True,
)
logger.info(companies.get_all())

Models as Entrypoints

You can also use the predefined models as entrypoints to the API:

from moloni.api import CustomersGetBySearchModel
from moloni.base import AuthConfig, MoloniBaseUrl
from pprint import pprint

auth_config = AuthConfig(
    client_id="your_client_id",
    client_secret="your_client_secret",
    username="your_username",  # Optional if refresh_token is set
    password="your_password",  # Optional if refresh_token is set
    refresh_token="your_refresh_token",  # Optional if username and password are set
)

with CustomersGetBySearchModel(company_id=5, search="cafe").connect(
    auth_config=auth_config
) as api:
    pprint(api.request().payload)
    

Minimal Configuration

For a minimal setup, credentials can be passed via environment variables:

from moloni.api.companies_client import CompaniesClient
from moloni.api.products_client import ProductsClient, ProductsGetAllModel
import logging 

logger = logging.getLogger(__name__)

companies = CompaniesClient()
logger.info(companies.get_all())
products = ProductsClient()
logger.info(products.get_all(dict(company_id=5, category_id=8231525)))

product = products.insert(
    dict(
        company_id=5,
        category_id=123456,
        unit_id=134568,
        has_stock="0",
        name="Name",
        reference="Reference",
        price="10",
        type="1",
        taxes=[{"tax_id": 123455, "order": 0, "cumulative": 0}],
    )
)

#  or with a model

products_response = products.get_all(
    ProductsGetAllModel(company_id=5, category_id=8231525)
)

Credentials

Passing Credentials

You can pass your credentials directly in the code or via environment variables:

from moloni.base import AuthConfig

auth_config = AuthConfig(
    client_id='your_client_id',
    client_secret='your_client_secret',
    username='your_username',
    password='your_password',
    refresh_token='your_refresh_token'
)

Environment Variables

Alternatively, set the following environment variables:

export MOLONI_CLIENT_ID="your_client_id"
export MOLONI_CLIENT_SECRET="your_client_secret"
export MOLONI_REFRESH_TOKEN="your_refresh_token"
export MOLONI_USERNAME="your_username"
export MOLONI_PASSWORD="your_password"

API Response Handling

The API responses are encapsulated in an ApiResponse object, which provides methods to access the response payload and handle pagination.

Example:

response = companies.get_all()
print(response.payload)  # Access the JSON payload
print(response.status_code)  # Check the HTTP status code

try:
    next_page = response.next(qty=10)
    print("Fetching next page with:", next_page)
except NoMoreRecords:
    print("No more records to fetch.")

Supported Endpoints

This client supports the full list of Moloni API endpoints, including:

•	BankaccountsClient
•	BillsofladingClient
•	CompaniesClient
•	CustomersClient
•	InvoicesClient
•	ProductsClient
•	WarehousesClient

For a full list, please refer to the documentation.

License

This project is licensed under the MIT License. See the LICENSE file for details.


Coverage


Disclaimer

We are not affiliated with Moloni, this is an unofficial wrapper to access their API. For more information, please visit their official website.

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

python_moloni_fix-0.3.16.tar.gz (45.6 kB view details)

Uploaded Source

Built Distribution

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

python_moloni_fix-0.3.16-py3-none-any.whl (91.2 kB view details)

Uploaded Python 3

File details

Details for the file python_moloni_fix-0.3.16.tar.gz.

File metadata

  • Download URL: python_moloni_fix-0.3.16.tar.gz
  • Upload date:
  • Size: 45.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for python_moloni_fix-0.3.16.tar.gz
Algorithm Hash digest
SHA256 8447eb420105fa4b49b4f70b1c38f86a3726fc6e9a7c2a5eb88b0d85dbece9ed
MD5 5e6b3e579c07984726b74e3c16f894b7
BLAKE2b-256 c2d8402875d80f78c37a41bb0ec3939132695ea8a9f738b3b5405a38e8d476fc

See more details on using hashes here.

File details

Details for the file python_moloni_fix-0.3.16-py3-none-any.whl.

File metadata

File hashes

Hashes for python_moloni_fix-0.3.16-py3-none-any.whl
Algorithm Hash digest
SHA256 974d1a25fd78fe139df20b87b7a43d05eae60c6d95c98a8259a39b7c0d7859cb
MD5 9646a522e1727d5216cc9097737bf5b7
BLAKE2b-256 a49843fef0be01c66753efcee2a82bc5d56df804a3b3abd480d7e54f0cc348fe

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