Skip to main content

A Python tool to build, manipulate, and interoperate with flexible graph structures

Project description

Description

annnet is a lightweight, flexible, minimal-dependencies Python package for creating, manipulating, and interoperating with diverse graph data structures. It aims to be the connective tissue ("glue") between multiple graph ecosystems (NetworkX, igraph, graph-tool, etc.) while maintaining a clean and general-purpose internal representation.


๐Ÿ“Œ Description

annnet provides a unified interface for:

  • Building general-purpose graphs (simple, directed, hyper, signed, etc.)
  • Managing node/edge annotations
  • Indexing and fast lookups
  • Importing from or exporting to various tools and file formats

Its design supports complex workflows in data science, bioinformatics, and network theory โ€” without locking you into a specific graph backend.


โœ… Features

General Graph Modeling

  • Simple graphs, directed graphs, multigraphs
  • Hypergraphs (via edge sets or higher-order relationships)
  • Signed and weighted edges
  • Rich node/edge annotations
  • Efficient indexing and lookups

Import Support

  • CSV, JSON, and flat files
  • Native import from existing objects:
    • networkx.Graph
    • igraph.Graph
    • graph_tool.Graph
    • corneto.Graph

Export & Interoperability

  • NetworkX (to_networkx())
  • igraph (to_igraph())
  • graph-tool (to_graphtool())
  • CORNETO
  • CSV, JSON, and custom serializations

Backend-specific Integration (if installed)

If networkx is installed, you can call any NetworkX algorithm directly using dot notation:

centrality = G.nx.degree_centrality()

How it works:

  1. annnet converts G to a NetworkX object on demand, abstracting away all the non-needed attributes.
  2. Runs the algorithm as-is.
  3. Returns results directly, syncing any graph changes back to the internal representation of the gg.Graph.

This allows you to access the full power of NetworkX algorithms with zero boilerplate.


๐Ÿ› ๏ธ Installation

To install annnet, you can use pip:

pip install annnet

Optional dependencies for extended functionality:

pip install annnet[networkx,igraph]
pip install annnet[graph-tool]
pip install annnet[corneto]

๐Ÿš€ Quick Start

import annnet as gg

# Create a new graph
G = gg.Graph(directed=True, backend="corneto")

# Add nodes and edges
G.add_node("A", type="gene")
G.add_node("B", type="protein")
G.add_edge("A", "B", sign="+", source="literature")

# Run a NetworkX algorithm (if installed)
path = G.nx.shortest_path(source="A", target="B")

# Export to JSON
G.to_json("graph.json")

๐Ÿ“ฆ Refined Package Structure

The package is organized to separate core functionality, I/O operations, adapters for external libraries, and algorithms. This modular design allows for easy extension and maintenance.

annnet/
โ”‚
โ”œโ”€โ”€ __init__.py                # Public API surface, version, re-exports
โ”œโ”€โ”€ _version.py                # Single source of truth for __version__
โ”‚
โ”œโ”€โ”€ core/                      # Core, always-installed logic
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ _base.py               # BaseGraph class and common interfaces 
โ”‚   โ”œโ”€โ”€ _graph.py              # Graph class and internal state manager
โ”‚   โ”œโ”€โ”€ structure.py           # Core data structures (nodes, edges, incidence)
โ”‚   โ”œโ”€โ”€ metadata.py            # Node/edge attribute store and access helpers
โ”‚   โ”œโ”€โ”€ views.py               # Subgraph views, shallow/deep copies
โ”‚   โ””โ”€โ”€ state.py               # Graph history, change tracking, and lazy loading
โ”‚
โ”œโ”€โ”€ io/                        # Loaders and writers for files
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ csv.py                 # CSV format (edge list, node table)
โ”‚   โ”œโ”€โ”€ json.py                # JSON or JSONL parsing (streamable)
โ”‚   โ”œโ”€โ”€ registry.py            # Entry point registration for loaders/dumpers
โ”‚   โ””โ”€โ”€ utils.py               # Format detection, path helpers
โ”‚
โ”œโ”€โ”€ adapters/                  # Lazy integration with external libraries
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ _base.py               # AbstractAdapter, adapter interface
โ”‚   โ”œโ”€โ”€ _proxy.py              # Tiny forwarding proxy
โ”‚   โ”œโ”€โ”€ manager.py             # Adapter registry and lazy bridge logic
โ”‚   โ”œโ”€โ”€ networkx.py            # If available: convert, cache, sync with NetworkX
โ”‚   โ”œโ”€โ”€ igraph.py              # If available
โ”‚   โ”œโ”€โ”€ graphtool.py           # If available
โ”‚   โ””โ”€โ”€ corneto.py             # If available
โ”‚
โ”œโ”€โ”€ algorithms/                # Pure-python algorithms using core only
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ””โ”€โ”€ traversal.py           # BFS/DFS etc.
โ”‚
โ””โ”€โ”€ utils/                     # Generic helpers not tied to graph structure
    โ”œโ”€โ”€ validation.py
    โ”œโ”€โ”€ typing.py
    โ””โ”€โ”€ config.py              # Global options, logging, toggles

โš™๏ธ Internal Design

annnet intelligently adapts its internal representation for performance and compatibility:

  • Chooses between edge lists, incidence matrices, and adjacency dicts automatically
  • Keeps metadata (node/edge attributes) separate from core structure
  • Lazy construction of external library representations (e.g., NetworkX) only when needed
  • Copy-on-write design for subgraphs and structural mutations

๐Ÿงญ Philosophy

annnet vis designed with these principles in mind:

  • Simple, consistent interface for all graph types
  • Interoperability-first: integrate, donโ€™t replace
  • Performance-aware, not performance-obsessed
  • Extendable and modular, not monolithic

๐Ÿ“œ License

annnet is licensed under the BSD-3 License. See the LICENSE file for details.

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

annnet-0.0.1.tar.gz (234.3 kB view details)

Uploaded Source

Built Distribution

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

annnet-0.0.1-py3-none-any.whl (124.7 kB view details)

Uploaded Python 3

File details

Details for the file annnet-0.0.1.tar.gz.

File metadata

  • Download URL: annnet-0.0.1.tar.gz
  • Upload date:
  • Size: 234.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for annnet-0.0.1.tar.gz
Algorithm Hash digest
SHA256 f8ba89101b3b974c98b0381d209275ed3334011b80d803ca50cf7a2942ac61c9
MD5 06a2b4d3136befdaeb45420df162dc44
BLAKE2b-256 c2da6ced88688a09ca860608292abb800e8a3cb026d4d2e160d886eb365c7d51

See more details on using hashes here.

File details

Details for the file annnet-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: annnet-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 124.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for annnet-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 eb8de870cbfb78c1427aefa711e3307d16f9ab2075f54e5311919fbee66f5425
MD5 02428bfa9a3c98b81d753a5962740572
BLAKE2b-256 20dfbfe48ed6268ff101aca50d3663623b6eea4951116d8c984546128653995a

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