Space Python Client
Python client library for Space, a pricing-driven self-adaptation platform for SaaS applications.
Table of Contents
- What You Get
- Requirements
- Installation
- Quick Start in 5 Minutes
- Configuration
- API Overview
- Data Models
- Caching
- WebSocket Events
- Error Handling
- Testing
- Contributing
- License
What You Get
- Simple API to connect to Space.
- Contract lifecycle operations.
- Feature evaluation with optional expected consumption.
- Revert operation for optimistic usage updates.
- Pricing token generation.
- Built-in in-memory cache and optional Redis cache.
- WebSocket events for real-time pricing updates.
Requirements
- Python 3.10+
Installation
pip install space-python-client
Optional Redis support:
pip install "space-python-client[redis]"
Quick Start in 5 Minutes
from space_client import SpaceClientFactory
client = SpaceClientFactory.connect(
"http://localhost:3000",
"your-api-key",
10_000,
)
healthy = client.is_connected_to_space()
print(f"Connected: {healthy}")
result = client.features.evaluate("user-123", "serviceA-featureX")
if result.error is not None:
print(f"Evaluation error: {result.error.message}")
else:
print(f"Feature enabled: {result.eval}")
pricing_token = client.features.generate_user_pricing_token("user-123")
print(f"Pricing token: {pricing_token}")
client.close()
Configuration
You can connect using either convenience factory arguments or SpaceConnectionOptions.
Option A: simple connection
from space_client import SpaceClientFactory
client = SpaceClientFactory.connect("http://localhost:3000", "your-api-key")
Option B: custom timeout
client = SpaceClientFactory.connect("http://localhost:3000", "your-api-key", 15000)
Option C: full options object
from space_client import SpaceClientFactory
from space_client.types import CacheOptions, SpaceConnectionOptions
options = SpaceConnectionOptions(
url="http://localhost:3000",
api_key="your-api-key",
timeout=15000,
cache=CacheOptions(enabled=True),
)
client = SpaceClientFactory.connect(options)
SpaceClientFactory.connect(...) validation rules:
- URL is required and must start with
http://orhttps://. - API key is required.
- Timeout must be a positive number.
API Overview
SpaceClientFactory
| Method | Description |
|---|---|
connect(options) |
Creates a client from full options and validates required inputs. |
connect(url, api_key) |
Convenience overload with default timeout (5000). |
connect(url, api_key, timeout) |
Convenience overload with custom timeout. |
SpaceClient
Main entry point. Exposes modules as public fields:
contractsfeaturescache
Core methods:
| Method | Returns | Details |
|---|---|---|
is_connected_to_space() |
bool |
HTTP health check against /healthcheck. |
on(event, callback) |
None |
Registers event callback for supported event names. |
remove_listener(event) |
None |
Removes one callback by event name. |
remove_all_listeners() |
None |
Removes all event callbacks. |
connect() |
None |
Connects/reconnects WebSocket namespace if disconnected. |
disconnect() |
None |
Disconnects WebSocket namespace. |
close() |
None |
Closes sockets, cache provider, and HTTP resources. |
Java-style aliases are also available (isConnectedToSpace, removeListener, removeAllListeners, etc.).
ContractModule
| Method | Returns |
|---|---|
get_contract(user_id) |
`Contract |
add_contract(contract_to_create) |
`Contract |
update_contract_subscription(user_id, new_subscription) |
`Contract |
update_contract_subscription_by_group_id(group_id, new_subscription) |
`list[Contract] |
update_contract_usage_levels(user_id, service_name, usage_levels_novations) |
`Contract |
remove_contract(user_id) |
None |
Java-style aliases are also available (getContract, addContract, etc.).
FeatureModule
| Method | Returns |
|---|---|
evaluate(user_id, feature_id, expected_consumption=None, details=False, server=False) |
FeatureEvaluationResult |
revert_evaluation(user_id, feature_id, revert_to_latest=True) |
bool |
generate_user_pricing_token(user_id) |
`str |
Java-style aliases are also available (revertEvaluation, generateUserPricingToken).
Data Models
Main model classes are exported from space_client.types:
SpaceConnectionOptionsCacheOptions,CacheType,ExternalCacheConfig,RedisConfigContract,ContractToCreate,SubscriptionFeatureEvaluationResult,EvaluationErrorBillingPeriod,BillingPeriodToCreate,ContractHistoryEntry,UsageLevel,UserContactSpaceEvent
Caching
Built-in cache is enabled with:
from space_client.types import CacheOptions, SpaceConnectionOptions
options = SpaceConnectionOptions(
url="http://localhost:3000",
api_key="your-api-key",
cache=CacheOptions(enabled=True),
)
Redis cache example:
from space_client.types import (
CacheOptions,
CacheType,
ExternalCacheConfig,
RedisConfig,
SpaceConnectionOptions,
)
options = SpaceConnectionOptions(
url="http://localhost:3000",
api_key="your-api-key",
cache=CacheOptions(
enabled=True,
type=CacheType.REDIS,
external=ExternalCacheConfig(
redis=RedisConfig(host="localhost", port=6379),
),
ttl=300,
),
)
WebSocket Events
Supported event names:
synchronizedpricing_createdpricing_archivedpricing_activedservice_disablederror
Example:
def on_pricing_created(details):
print("Pricing changed:", details)
client.on("pricing_created", on_pricing_created)
client.connect()
Error Handling
- Factory validation raises
ValueErrorfor invalid input. - Runtime HTTP failures are converted to
None/Falsereturn values where appropriate. FeatureModule.evaluate(...)returns an object containingerrorwhen request handling fails.
Testing
Run tests locally:
pip install -e .[dev]
pytest
CI executes tests on every pull request for Python 3.10, 3.11, and 3.12.
Contributing
- Create a branch from
main. - Add or update tests for every behavior change.
- Open a pull request.
License
MIT License.
Metadata
Release files for space-python-client 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| space_python_client-0.2.0.tar.gz | 42.4 kB | With provenance | Details for space_python_client-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| space_python_client-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for space_python_client-0.2.0-py3-none-any.whl |
Total release size: 66.4 kB
Release files / space_python_client-0.2.0.tar.gz
| Download URL | space_python_client-0.2.0.tar.gz |
|---|---|
| Size | 42.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1b8365b75cd4d505e24f826df605768be6d471917046b849244c75794640875b
|
|
BLAKE2b-256 checksum How to use checksums |
c119ba4c7f8e5abd19d9367a3920e90e9376c5c9007e55bb9a94839cbb42f671
|
| 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 Jul 31, 2026.
Transparency logRelease files / space_python_client-0.2.0-py3-none-any.whl
| Download URL | space_python_client-0.2.0-py3-none-any.whl |
|---|---|
| Size | 24.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0837622675ef090e17f60fc4f2f6b48319db54a456092309297921a320bf6d70
|
|
BLAKE2b-256 checksum How to use checksums |
cf148fad47375761b3bb83f0b4cd37572af53ff341a783b8423bfc43ff35e8f0
|
| 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 Jul 31, 2026.
Transparency logSecurity for space-python-client 0.2.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
Both files in this release have been uploaded with provenance metadata.
Attestation for space_python_client-0.2.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 Jul 31, 2026.
Transparency logA 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.