A simple Python client to interact with Cisco FMC or SCC APIs using operationId from the OpenAPI spec.
Project description
FMC OpenAPI
fmc_openapi is a Python package that simplifies interaction with Cisco Firepower Management Center (FMC) APIs. It dynamically parses the OpenAPI (Swagger) specification to discover available endpoints and interact with them using the operationId.
To identify which operations are supported, you can refer to the Operation ID table.
🚀 Features
- 🔍 Parses the Swagger file to discover endpoints
- 💡 Calls API operations by operationId
- 🔐 Session handling (login/logout)
- 🧰 Simplifies complex API interactions
- ⚠️ Error handling built-in
- 🏢 SCC/CDO Token-Based Authentication
- 🔄 Automatic pagination handling (manual pagination is also possible)
- 📦 Bulk operations
- 📄 All endpoints defined in the Swagger spec
📦 Installation
pip install fmc_openapi
Import API client
from fmc_openapi import FMCOpenAPIClient
🧑💻 Usage Example
Connecting to FMC (username/password)
from fmc_openapi import FMCOpenAPIClient
with FMCOpenAPIClient(
hostname="fmc.example.com",
username="your_username",
password="your_password",
verify=False
) as fmc:
domains = fmc.operation("getAllDomain")
Connecting to SCC (token-based)
from fmc_openapi import FMCOpenAPIClient
with FMCOpenAPIClient(
hostname="scc.example.com",
token="your_token_here",
verify=False
) as fmc:
domains = fmc.operation("getAllDomain")
Get all access policy rules
import jmespath
with FMCOpenAPIClient(
hostname="fmc.example.com",
username="your_username",
password="your_password",
verify=False
) as fmc:
# Get domain UUID
domains = fmc.operation("getAllDomain")
domain_uuid = jmespath.search("items[?name=='my-domain'].uuid | [0]", domains)
# Get ACP UUID
acp_response = fmc.operation("getAllAccessPolicy", domainUUID=domain_uuid)
acp_uuid = jmespath.search("items[?name=='my-policy'].uuid | [0]", acp_response)
# Get all access policy rules (with automatic pagination)
rules = fmc.operation(
"getAllAccessRule",
limit=1000,
domainUUID=domain_uuid,
containerUUID=acp_uuid,
expanded=True
)
Manual Pagination
rules = fmc.operation(
"getAllAccessRule",
limit=1000,
domainUUID=domain_uuid,
containerUUID=acp_uuid,
expanded=True,
manual_pagination=True
)
Creating Objects
payload = {
"name": "obj-192.168.1.0",
"type": "Network",
"value": "192.168.1.0/24",
}
fmc.operation("createMultipleNetworkObject", payload=payload, domainUUID=domain_uuid)
Bulk Operations
response = fmc.operation(
"getHitCount",
limit=1000,
domainUUID=domain_uuid,
containerUUID=ac_uuid_selected,
filter=f"deviceId:{device_uuid}",
expanded=True,
bulk=True
)
🧪 Running Tests
Tests are written using pytest.
To run tests:
poetry run pytest
Or activate the environment first:
poetry shell
pytest
🛠 Project Structure
fmc_openapi/
├── __init__.py # Imports FMCOpenAPIClient
├── client.py # Main client class
├── swagger.py # Swagger parser
├── utils.py # Logging and request helpers
tests/
├── test_swagger.py # Tests for Swagger JSON fetching and operation extraction
├── test_operation.py # Tests for executing API operations using operationId
├── test_auth.py # Tests for authentication: login and logout
├── test_client.py # General client behavior and utility method tests
📄 License
GNU GPL v3 License. See LICENSE for details.
🤝 Contributing
Pull requests are welcome! If you plan to add new features, open an issue first to discuss it.
- Fork the project
- Create your feature branch
- Commit your changes
- Push to the branch
- Open a pull request
✉️ Contact
Questions? Ideas? Open an issue or drop a message.
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
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 fmc_openapi-0.1.3.tar.gz.
File metadata
- Download URL: fmc_openapi-0.1.3.tar.gz
- Upload date:
- Size: 19.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.11.12 Linux/6.11.0-1014-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
821603d7771bdac5ac10d4897054b2c5dfc7a4e60ea528659c43e9c974a7731f
|
|
| MD5 |
08582886cc76812c5515f6880164973b
|
|
| BLAKE2b-256 |
b99c0cf28970eced32b68db0daa497b60753c0286a5345647705ac400ac2372c
|
File details
Details for the file fmc_openapi-0.1.3-py3-none-any.whl.
File metadata
- Download URL: fmc_openapi-0.1.3-py3-none-any.whl
- Upload date:
- Size: 22.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.11.12 Linux/6.11.0-1014-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c0ac3281e5ba3690b53efc659520218475fbddc0fffc77854a309dd47570aac0
|
|
| MD5 |
05aef717b05d320fc6aefc65e9075100
|
|
| BLAKE2b-256 |
851477926a408ee30eb013623daef35890fbd5778cac485b621edfcf2195b977
|