Modern Python client for the 24SevenOffice API
Project description
py24so
A modern Python client for the 24SevenOffice API with support for synchronous and asynchronous operations, caching, rate limiting, and batch requests.
Features
- Full support for customers, products, and invoices
- Both synchronous and asynchronous clients
- Built-in caching support
- Automatic rate limiting
- Batch operations for efficient API usage
- Proper error handling with custom exceptions
- Comprehensive documentation and type hints
- 100% test coverage
Installation
# Using pip (standard)
pip install py24so
# With HTTP/2 support (for better performance)
pip install py24so[http2]
# Using UV (faster installation)
uv pip install py24so
# With HTTP/2 support using UV
uv pip install py24so[http2]
Quick Start
Synchronous Usage
from py24so import Client24SO
from py24so.models.customer import CustomerCreate
# Initialize the client
client = Client24SO(
client_id="your-client-id",
client_secret="your-client-secret",
organization_id="your-organization-id"
)
# List customers
customers = client.customers.list(page=1, page_size=10)
for customer in customers:
print(f"{customer.name} ({customer.id})")
# Create a customer
new_customer = CustomerCreate(
name="Acme Inc.",
email="info@acme.com",
phone="123-456-7890"
)
created_customer = client.customers.create(new_customer)
print(f"Created customer: {created_customer.name} (ID: {created_customer.id})")
# Always close the client when done
client.close()
Asynchronous Usage
import asyncio
from py24so import AsyncClient24SO
from py24so.models.invoice import InvoiceCreate, InvoiceLineItem
async def main():
# Initialize the async client
async with AsyncClient24SO(
client_id="your-client-id",
client_secret="your-client-secret",
organization_id="your-organization-id"
) as client:
# Create an invoice
invoice = InvoiceCreate(
customer_id="customer-id",
line_items=[
InvoiceLineItem(
description="Product A",
quantity=2,
unit_price=99.99,
vat_rate=25.0
)
]
)
created_invoice = await client.invoices.create(invoice)
print(f"Created invoice: {created_invoice.invoice_number}")
# Send the invoice
sent_invoice = await client.invoices.send(created_invoice.id)
print(f"Invoice status: {sent_invoice.status}")
# Run the async function
asyncio.run(main())
Context Managers
The clients also support context managers for automatic resource cleanup:
# Synchronous context manager
with Client24SO(
client_id="your-client-id",
client_secret="your-client-secret",
organization_id="your-organization-id"
) as client:
# Client is automatically closed when exiting the block
customers = client.customers.list()
Configuration Options
You can customize the client behavior using the ClientOptions class:
from py24so import Client24SO
from py24so.models.config import ClientOptions
options = ClientOptions(
# Enable caching
cache_enabled=True,
# Cache TTL in seconds (5 minutes)
cache_ttl=300,
# Maximum number of cached responses
cache_max_size=1000,
# Rate limit in requests per minute
rate_limit_rate=30,
# Enable HTTP/2
http2=True,
# Custom headers
headers={"X-Custom-Header": "value"},
# Request timeout in seconds
timeout=30.0
)
client = Client24SO(
client_id="your-client-id",
client_secret="your-client-secret",
organization_id="your-organization-id",
options=options
)
Development
Setup
-
Clone the repository:
git clone https://github.com/yourusername/py24so.git cd py24so
-
Install development dependencies:
pip install -e ".[dev]"
-
Run the tests:
pytest
Code Formatting
This project uses Black and isort for code formatting. You can format the code using:
# Run the formatting script
python scripts/format_code.py
# Or run the tools directly
black py24so tests
isort py24so tests
If the CI checks are failing due to formatting issues, you can:
- Run the formatting script locally and push the changes
- Use the "Format Code" GitHub Action in your repository
Contributing
- Fork the repository
- Create a feature branch
- Add your changes
- Run tests and ensure they pass
- Submit a pull request
GitHub Actions
This project includes GitHub Actions for continuous integration and deployment:
-
CI: Runs on every push to main and on pull requests to main
- Tests on multiple Python versions
- Code quality checks
- Code coverage reporting with Codecov
-
Publish to PyPI: Triggered on new releases or manually
- Builds the package
- Runs tests
- Publishes to PyPI if all checks pass
-
Format Code: Format code automatically with Black and isort
- Can be triggered manually
- Automatically fixes code style issues
Setting Up GitHub Actions
To use these GitHub Actions, you need to set up some secrets in your repository:
-
PyPI Token (for package publishing):
- Generate a token on PyPI: https://pypi.org/manage/account/token/
- Add it as a repository secret named
PYPI_API_TOKEN
-
Codecov Token (for code coverage reporting):
- Create an account on Codecov and link your repository
- Get your repository upload token from Codecov
- Add it as a repository secret named
CODECOV_TOKEN
Manual Release
To manually trigger a release:
- Go to the Actions tab in your GitHub repository
- Select the "Publish to PyPI" workflow
- Click "Run workflow"
- Enter the version number (e.g., "0.1.1") and submit
Note: You need to add a PyPI API token as a secret in your GitHub repository settings:
- Generate a token on PyPI: https://pypi.org/manage/account/token/
- Add it as a repository secret named
PYPI_API_TOKEN
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file py24so-0.2.1.tar.gz.
File metadata
- Download URL: py24so-0.2.1.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3afea5b718478242d732e78f3a6b4df5094c493385c7949eafc904c4fb355731
|
|
| MD5 |
ff0763ceee31bbd849d5343533fb95bb
|
|
| BLAKE2b-256 |
f1da1d2f88a12d5df79311d1d33d0c2de6dcdf57fcc61af790406b168054a8dc
|
Provenance
The following attestation bundles were made for py24so-0.2.1.tar.gz:
Publisher:
publish-to-pypi.yml on sondreal/py24so
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
py24so-0.2.1.tar.gz -
Subject digest:
3afea5b718478242d732e78f3a6b4df5094c493385c7949eafc904c4fb355731 - Sigstore transparency entry: 192561829
- Sigstore integration time:
-
Permalink:
sondreal/py24so@346314eecd288bf8d35a5c78ed0b20559ebb3391 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/sondreal
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@346314eecd288bf8d35a5c78ed0b20559ebb3391 -
Trigger Event:
release
-
Statement type:
File details
Details for the file py24so-0.2.1-py3-none-any.whl.
File metadata
- Download URL: py24so-0.2.1-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
06d9c78355eb0a5f2fa363f66bb0be262e18b2a59df8f843fa99640cf4294673
|
|
| MD5 |
2c67eb80e37e25b64147ef011b9c6838
|
|
| BLAKE2b-256 |
701edbb6be3f4af06906acfd128e82f19ce8a7d627b4d980f35db2a804fc9789
|
Provenance
The following attestation bundles were made for py24so-0.2.1-py3-none-any.whl:
Publisher:
publish-to-pypi.yml on sondreal/py24so
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
py24so-0.2.1-py3-none-any.whl -
Subject digest:
06d9c78355eb0a5f2fa363f66bb0be262e18b2a59df8f843fa99640cf4294673 - Sigstore transparency entry: 192561830
- Sigstore integration time:
-
Permalink:
sondreal/py24so@346314eecd288bf8d35a5c78ed0b20559ebb3391 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/sondreal
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@346314eecd288bf8d35a5c78ed0b20559ebb3391 -
Trigger Event:
release
-
Statement type: